package ctop.bytedance.ad.common.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;

import java.util.Date;

/**
 * @Description: 文件信息
 * @Author: jeecg-boot
 * @Date: 2019-07-28
 * @Version: V1.0
 */
@Data
@TableName("ctop_file_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "ctop_file_info对象", description = "文件信息")
public class FileInfo {

    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "id")
    private Long id;
    /**
     * 文件名称
     */
    @Excel(name = "文件名称", width = 15)
    @ApiModelProperty(value = "文件名称")
    private String fileName;

    /**
     * md5
     */
    @Excel(name = "md5", width = 15)
    @ApiModelProperty(value = "文件MD5值")
    private String md5;

    /**
     * 平台文件id
     */
    @Excel(name = "平台文件id")
    @ApiModelProperty(value = "平台文件id")
    private String fileId;

    /**
     * 文件类型
     */
    @Excel(name = "文件类型", width = 15)
    @ApiModelProperty(value = "文件类型")
    private String type;

    /**
     * 文件类型
     */
    @Excel(name = "所属平台类型", width = 15)
    @ApiModelProperty(value = "所属平台类型")
    private String platformType;

    /**
     * 文件访问路径
     */
    @Excel(name = "文件地址", width = 15)
    @ApiModelProperty(value = "文件地址")
    private String path;

    @Excel(name = "头条账号id", width = 15)
    @ApiModelProperty(value = "头条账号id")
    private Long accountId;

    @Excel(name = "广告主id", width = 15)
    @ApiModelProperty(value = "广告主id")
    private String advertiserId;

    @Excel(name = "文件访问路径", width = 15)
    @ApiModelProperty(value = "文件访问路径")
    private String fileUrl;
    /**
     * createTime
     */
    @ApiModelProperty(value = "createTime")
    private Date createTime;
    /**
     * updateTime
     */
    @ApiModelProperty(value = "updateTime")
    private Date updateTime;

    public FileInfo(String md5Hex, JSONObject data, String advertiserId, CtopOauthToken token, String imageUrl, String imagePath, String fileType, String platformType) {
        this.type = fileType;
        if ("IMAGE".equals(type)) {
            this.fileId = data.getString("id");
        } else {
            this.fileId = data.getString("video_id");
        }
        this.fileName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
        this.accountId = token.getAccountId();
        this.advertiserId = token.getAdvertiserId();
        this.fileUrl = imageUrl;
        this.path = imagePath;
        this.platformType = platformType;
        this.md5 = md5Hex;
    }

    public FileInfo() {
    }

    @Override
    public String toString() {
        return "FileInfo{" +
                "id=" + id +
                ", fileName='" + fileName + '\'' +
                ", type='" + type + '\'' +
                ", platformType='" + platformType + '\'' +
                ", path='" + path + '\'' +
                ", fileUrl='" + fileUrl + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}
