package com.xxl.job.executor.material.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xxl.job.executor.common.entity.CtopOauthToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @Description: 今日头条视频素材信息
 * @Author: jeecg-boot
 * @Date: 2019-07-29
 * @Version: V1.0
 */
@Data
@TableName("ctop_bytedance_video_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ByteDanceVideoInfo {

    /**
     * id
     */
    @TableId
    private String id;
    private String vid;
    /**
     * 对应本文件id
     */
    private String fileId;
    /**
     * 平台账号id
     */
    private String advertiserId;
    /**
     * 对应本文件id
     */
    private Long accountId;
    /**
     * 视频宽度
     */
    private Integer width;
    /**
     * 视频高度
     */
    private Integer height;
    /**
     * 视频时长
     */
    private Double duration;
    /**
     * 视频大小
     */
    private Long size;
    /**
     * 视频地址
     */
    private String videoUrl;
    private String signature;
    private Integer status;
    private Date createTime;
    private Date updateTime;
    private String url;
    private String format;
    private String posterUrl;
    private Long bitRate;
    private Long materialId;
    private String source;
    private Date materialUploadTime;
    private String filename;
    private Integer type;

    public ByteDanceVideoInfo(JSONObject data, CtopOauthToken token) {
        this.id = data.getString("id")+token.getAccountId();
        this.vid = data.getString("id");
        this.fileId = data.getString("video_id");
        this.accountId = token.getAccountId();
        this.advertiserId = token.getAdvertiserId();
        this.width = data.getInteger("width");
        this.height = data.getInteger("height");
        this.size = data.getLong("size");
        this.duration = data.getDouble("duration");
        this.videoUrl = "https://aweme.snssdk.com/aweme/v1/playwm/?video_id="+data.getString("id")+"&line=0";
        this.signature = data.getString("signature");
        this.status = 1;
        this.source = data.getString("source");
        this.materialId = data.getLong("material_id");
        this.bitRate = data.getLong("bit_rate");
        this.posterUrl = data.getString("poster_url");
        this.format = data.getString("format");
        this.url = data.getString("url");
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
        this.materialUploadTime = data.getDate("create_time");
        this.filename = data.getString("filename");
    }

    public ByteDanceVideoInfo() {
    }
}
