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

import com.google.gson.annotations.SerializedName;
import com.tofly.ghrq_route.base.url.NetRequestURL;
import com.tofly.ghrq_route.module.uploadFile.domain.UploadFileBean;
import com.tofly.ghrq_route.common.util.file.FileUtil;

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;

/**
 * Created by zombiexq on 2016/6/23.
 */
@Entity(nameInDb = "DB_TROUBLE_PICTURE")
@SuppressWarnings("serial")
public class TroublePictureBean implements Serializable{

    public final static int PHOTO_DELETED_STATE = -2;
    public final static int PHOTO_SAVED_STATE = -1;
    public final static int PHOTO_LOCAL_STATE = 0;
    public final static int PHOTO_UPLOADING = 1;
    public final static int PHOTO_UPLOADED = 2;
    public final static int PHOTO_UPLOAD_FAILED = 3;

    public final static String FILE_VIDEO_TYPE = "video";
    public final static String FILE_IMAGE_TYPE = "image";

    @Id @NotNull @Unique
    private String id;
    private String troubleid;
    private String filetype;
    private String filenote;
    private String file;     //fileName

    private String thumb;  //服务器缩略图
    @SerializedName(value = "filepath", alternate = "filename")
    private String filepath;  //本地路径
    private String fileurl;   //服务器端地址
    private String filethumb;  //本地缩略图地址
    private long second = 0;     //时长,单位毫秒
    private int status;
    @SerializedName(value = "createTime", alternate = "check_time")
    private String createTime;


    @Generated(hash = 1225127154)
    public TroublePictureBean(@NotNull String id, String troubleid, String filetype,
            String filenote, String file, String thumb, String filepath,
            String fileurl, String filethumb, long second, int status,
            String createTime) {
        this.id = id;
        this.troubleid = troubleid;
        this.filetype = filetype;
        this.filenote = filenote;
        this.file = file;
        this.thumb = thumb;
        this.filepath = filepath;
        this.fileurl = fileurl;
        this.filethumb = filethumb;
        this.second = second;
        this.status = status;
        this.createTime = createTime;
    }

    @Generated(hash = 48574441)
    public TroublePictureBean() {

    }

    public TroublePictureBean(TroublePictureBean pictureBean) {
        this.id = pictureBean.id;
        this.troubleid = pictureBean.troubleid;
        this.filetype = pictureBean.filetype;
        this.filenote = pictureBean.filenote;
        this.file = pictureBean.file;
        this.filepath = pictureBean.filepath;
        this.filethumb = pictureBean.filethumb;
        this.second = pictureBean.second;
        this.status = pictureBean.status;
        this.createTime = pictureBean.createTime;
    }

    public String getId() {
        return id;
    }

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

    public String getTroubleid() {
        return troubleid;
    }

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

    public String getFiletype() {
        return filetype;
    }

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

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath;
    }

    public int getStatus() {
        return status;
    }

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

    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 UploadFileBean getUploadFileBean(){
        UploadFileBean uploadFileBean = new UploadFileBean();
        uploadFileBean.setId(id);
        uploadFileBean.setUpload_time(createTime);
        uploadFileBean.setFilenote(filenote);
        uploadFileBean.setTableid(troubleid);
        uploadFileBean.setFilename(file);
        uploadFileBean.setFilepath(filepath);
        return uploadFileBean;
    }

    public String getRealPath(){
        String url = file;
        String real_path = filepath;
        if (real_path == null || !FileUtil.fileExists(real_path)) {
            real_path = NetRequestURL.getHttpHead() + url;
        }
        return real_path;
    }

    public String getThumb() {
        return thumb;
    }

    public void setThumb(String thumb) {
        this.thumb = thumb;
    }

    public String getFileurl() {
        return this.fileurl;
    }

    public void setFileurl(String fileurl) {
        this.fileurl = fileurl;
    }

    public String getFilethumb() {
        return this.filethumb;
    }

    public void setFilethumb(String filethumb) {
        this.filethumb = filethumb;
    }

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

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