package com.tofly.ghrq_route.module.trouble.domain;

import com.gaoyuan.weixinrecord.example.Record;
import com.google.gson.annotations.SerializedName;
import com.tofly.ghrq_route.module.uploadFile.domain.UploadFileBean;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Unique;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by Amu on 2017/4/6.
 */

@Entity(nameInDb = "DB_TROUBLE_AUDIO")
@SuppressWarnings("serial")
public class TroubleAudioBean implements Serializable {
    @Id @NotNull @Unique
    private String id;
    private String troubleid;
    @SerializedName(value = "path", alternate = "filename")
    private String path;
    private String url;
    @SerializedName(value = "second", alternate = "audiolength")
    private int second;
    private String filetype;
    private String filenote;
    private int status;
    @SerializedName(value = "createTime", alternate = "check_time")
    private String createTime;

    @Generated(hash = 2093104503)
    public TroubleAudioBean(@NotNull String id, String troubleid, String path,
                            String url, int second, String filetype, String filenote, int status,
                            String createTime) {
        this.id = id;
        this.troubleid = troubleid;
        this.path = path;
        this.url = url;
        this.second = second;
        this.filetype = filetype;
        this.filenote = filenote;
        this.status = status;
        this.createTime = createTime;
    }

    @Generated(hash = 48133867)
    public TroubleAudioBean() {
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTroubleid() {
        return this.troubleid;
    }

    public void setTroubleid(String troubleid) {
        this.troubleid = troubleid;
    }

    public String getPath() {
        return this.path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getSecond() {
        return this.second;
    }

    public void setSecond(int second) {
        this.second = second;
    }

    public String getFiletype() {
        return this.filetype;
    }

    public void setFiletype(String filetype) {
        this.filetype = filetype;
    }

    public int getStatus() {
        return this.status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getFilenote() {
        return this.filenote;
    }

    public void setFilenote(String filenote) {
        this.filenote = filenote;
    }

    public Record getAudioRecord(){
        Record record = new Record();
        record.setPath(this.path);
        record.setCreateTime(this.createTime);
        record.setSecond(this.second);
        return record;
    }

    public static List<Record> getAudioRecords(List<TroubleAudioBean> audioBeans){
        List<Record> records = new ArrayList<>();
        if (audioBeans != null){
            for (TroubleAudioBean audioBean : audioBeans){
                if (audioBean != null) {
                    Record record = audioBean.getAudioRecord();
                    records.add(record);
                }
            }
        }
        return records;
    }

    public static TroubleAudioBean getAudioBean(Record record){
        String audioid = UUID.randomUUID().toString();
        TroubleAudioBean audioBean = new TroubleAudioBean();
        audioBean.setId(audioid);
        audioBean.setPath(record.getPath());
        audioBean.setCreateTime(record.getCreateTime());
        audioBean.setSecond(record.getSecond());
        audioBean.setFilenote(record.getFilenote());
        return audioBean;
    }

    public static List<TroubleAudioBean> getAudioBeans(List<Record> records){
        List<TroubleAudioBean> audioBeans = new ArrayList<>();
        if (records != null){
            for (Record record : records){
                if (record != null){
                    TroubleAudioBean audioBean = getAudioBean(record);
                    audioBeans.add(audioBean);
                }
            }
        }
        return audioBeans;
    }

    public UploadFileBean getUploadFileBean(){
        UploadFileBean uploadFileBean = new UploadFileBean();
        uploadFileBean.setId(id);
        uploadFileBean.setFilename(url);
        uploadFileBean.setFilepath(path);
        uploadFileBean.setAudiolength(second + "");
        uploadFileBean.setTableid(troubleid);
        uploadFileBean.setFilenote(filenote);
        uploadFileBean.setUpload_time(createTime);
        return uploadFileBean;
    }
}
