package cn.com.ctop.toutiao.modules.material.entity;

import cn.com.ctop.common.module.entity.CtopOauthToken;
import com.alibaba.fastjson.JSONObject;
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;

/**
 * 头条图片素材
 * @author jeecg-boot
 * @date   2020-08-01
 * @version V1.0
 */
@Data
@TableName("ctop_bytedance_image_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="ctop_bytedance_image_info对象", description="头条图片素材")
public class BytedanceImageInfo {

	/**id*/
	@TableId()
    @ApiModelProperty(value = "id")
	private String id;
	/**头条平台账号id*/
	private Long accountId;
	/**advertiserId*/
	private Long materialId;
	/**图片大小*/
	@Excel(name = "图片大小", width = 15)
    @ApiModelProperty(value = "图片大小")
	private Long size;
	/**图片宽度*/
	@Excel(name = "图片宽度", width = 15)
    @ApiModelProperty(value = "图片宽度")
	private Long width;
	/**图片高度*/
	@Excel(name = "图片高度", width = 15)
    @ApiModelProperty(value = "图片高度")
	private Long height;
	/**预览地址*/
	@Excel(name = "预览地址", width = 15)
    @ApiModelProperty(value = "预览地址")
	private String url;
	private String imageUrl;
	/**图片格式*/
	@Excel(name = "图片格式", width = 15)
    @ApiModelProperty(value = "图片格式")
	private String format;
	/**图片Md5*/
	@Excel(name = "图片Md5", width = 15)
    @ApiModelProperty(value = "图片Md5")
	private String signature;
	private String imageCreateTime;
	private String fileName;
	/**createTime*/
    @ApiModelProperty(value = "createTime")
	private Date createTime;
	/**updateTime*/
    @ApiModelProperty(value = "updateTime")
	private Date updateTime;
    private Integer type;

	public BytedanceImageInfo(JSONObject dataObject, CtopOauthToken token) {
		String id = dataObject.getString("id");
		if(null!=id&&id.contains("web")){
			this.imageUrl = "https://sf6-ttcdn-tos.pstatp.com/obj/"+id;
		}else{
			this.imageUrl = "https://sf6-ttcdn-tos.pstatp.com/obj/mosaic-legacy/"+id;
		}
		this.id = dataObject.getString("id");
		this.accountId = token.getAccountId();
		this.materialId = dataObject.getLong("material_id");
		this.size = dataObject.getLong("size");
		this.width = dataObject.getLong("width");
		this.height = dataObject.getLong("height");
		this.url = dataObject.getString("url");
		this.format = dataObject.getString("format");
		this.signature = dataObject.getString("signature");
		this.imageCreateTime = dataObject.getString("create_time");
		this.fileName = dataObject.getString("filename");
		this.createTime = new Date();
		this.updateTime = new Date();
	}

	public BytedanceImageInfo() {
	}
}
