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

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 cn.com.ctop.common.module.entity.CtopOauthToken;
import org.jeecgframework.poi.excel.annotation.Excel;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 今日头条广告组信息
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-07-22
 */
@Data
@TableName("ctop_bytedance_campaign")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "ctop_bytedance_campaign对象", description = "今日头条广告组信息")
public class ByteDanceCampaign {

    /**
     * 今日头条广告组id
     */
    @TableId
    @ApiModelProperty(value = "今日头条广告组id")
    private Long id;
    /**
     * 平台用户id
     */
    @Excel(name = "平台用户id", width = 15)
    @ApiModelProperty(value = "平台用户id")
    private String advertiserId;
    /**
     * 头条账号id
     */
    @Excel(name = "头条账号id", width = 15)
    @ApiModelProperty(value = "头条账号id")
    private Long toutiaoId;
    /**
     * 头条账号id
     */
    @Excel(name = "模板id", width = 15)
    @ApiModelProperty(value = "模板id")
    private Long templateId;
    /**
     * 广告组名称
     */
    @Excel(name = "广告组名称", width = 15)
    @ApiModelProperty(value = "广告组名称")
    private String name;
    /**
     * 广告组预算
     */
    @Excel(name = "广告组预算", width = 15)
    @ApiModelProperty(value = "广告组预算")
    private BigDecimal budget;
    /**
     * 广告组预算类型
     */
    @Excel(name = "广告组预算类型", width = 15)
    @ApiModelProperty(value = "广告组预算类型")
    private String budgetMode;
    /**
     * 广告组推广目的
     */
    @Excel(name = "广告组推广目的", width = 15)
    @ApiModelProperty(value = "广告组推广目的")
    private String landingType;
    /**
     * 广告组时间戳,用于更新时提交,服务端判断是否基于最新信息修改
     */
    @Excel(name = "广告组时间戳,用于更新时提交,服务端判断是否基于最新信息修改", width = 15)
    @ApiModelProperty(value = "广告组时间戳,用于更新时提交,服务端判断是否基于最新信息修改")
    private String modifyTime;
    @Excel(name = "广告组状态", width = 15)
    @ApiModelProperty(value = "广告组状态")
    private String status;
    /**
     * optStatus
     */
    @Excel(name = "optStatus", width = 15)
    @ApiModelProperty(value = "optStatus")
    private String optStatus;
    /**
     * 广告组创建时间
     */
    @Excel(name = "广告组创建时间", width = 15)
    @ApiModelProperty(value = "广告组创建时间")
    private String campaignCreateTime;
    /**
     * 广告组修改时间
     */
    @Excel(name = "广告组修改时间", width = 15)
    @ApiModelProperty(value = "广告组修改时间")
    private String campaignModifyTime;
    /**
     * createTime
     */
    @ApiModelProperty(value = "createTime")
    private Date createTime;
    /**
     * updateTime
     */
    @ApiModelProperty(value = "updateTime")
    private Date updateTime;

    public ByteDanceCampaign() {
    }

    public ByteDanceCampaign(Long id, String advertiserId, Long toutiaoId, String name, BigDecimal budget, String budgetMode, String landingType, String modifyTime, String status, String optStatus, String campaignCreateTime, String campaignModifyTime, Date createTime, Date updateTime) {
        this.id = id;
        this.advertiserId = advertiserId;
        this.toutiaoId = toutiaoId;
        this.name = name;
        this.budget = budget;
        this.budgetMode = budgetMode;
        this.landingType = landingType;
        this.modifyTime = modifyTime;
        this.status = status;
        this.optStatus = optStatus;
        this.campaignCreateTime = campaignCreateTime;
        this.campaignModifyTime = campaignModifyTime;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }

    public ByteDanceCampaign(JSONObject dataObject, String accountId) {
        Long id = dataObject.getLong("id");
        this.id = id;
        this.advertiserId = accountId;
        Long toutiaoId = dataObject.getLong("advertiser_id");
        if (null != toutiaoId) {
            this.toutiaoId = toutiaoId;
        }
        String name = dataObject.getString("name");
        if (null != name && !"".equals(name.trim())) {
            this.name = name;
        }
        BigDecimal budget = dataObject.getBigDecimal("budget");
        if (null != budget) {
            this.budget = budget;
        }
        String budgetMode = dataObject.getString("budget_mode");
        if (null != budgetMode && !"".equals(budgetMode.trim())) {
            this.budgetMode = budgetMode;
        }
        String landingType = dataObject.getString("landing_type");
        if (null != landingType && !"".equals(landingType.trim())) {
            this.landingType = landingType;
        }
        String modifyTime = dataObject.getString("modify_time");
        if (null != modifyTime && !"".equals(modifyTime.trim())) {
            this.modifyTime = modifyTime;
        }
        String status = dataObject.getString("status");
        if (null != status && !"".equals(status.trim())) {
            this.status = status;
        }
        String optStatus = dataObject.getString("opt_status");
        if (null != optStatus && !"".equals(optStatus.trim())) {
            this.optStatus = optStatus;
        }
        String campaignCreateTime = dataObject.getString("campaign_create_time ");
        if (null != campaignCreateTime && !"".equals(campaignCreateTime.trim())) {
            this.campaignCreateTime = campaignCreateTime;
        }
        String campaignModifyTime = dataObject.getString("campaign_modify_time");
        if (null != campaignModifyTime && !"".equals(campaignModifyTime.trim())) {
            this.campaignModifyTime = campaignModifyTime;
        }
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
    }

    public ByteDanceCampaign(Long id, CtopOauthToken oauthToken, String campaignName, String budgetMode, Integer budget, String landingType) {
        this.id = id;
        this.advertiserId = oauthToken.getAdvertiserId();
        this.name = campaignName;
        this.budgetMode = budgetMode;
        this.budget = BigDecimal.valueOf(budget);
        this.landingType = landingType;
        this.toutiaoId = oauthToken.getAccountId();
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
    }
}
