package org.jeecg.modules.bytedance.advertise.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.modules.bytedance.common.entity.CtopOauthToken;

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
    private Long id;
    private Long accountId;
    /**
     * 广告组名称
     */
    private String name;
    /**
     * 广告组预算
     */
    private BigDecimal budget;
    /**
     * 广告组预算类型
     */
    @Dict(dicCode = "item_value", dictTable = "sys_dict_item", dicText = "item_text",extendsKey = "dict_id",extendsValue = "6512a5e70b99f6499dc3164b95e06395")
    private String budgetMode;
    /**
     * 广告组推广目的
     * extendsValue在此处为固定值，切忌胡乱修改
     */
    @Dict(dicCode = "item_value", dictTable = "sys_dict_item", dicText = "item_text",extendsKey = "dict_id",extendsValue = "181afbae847dd3bc7e27795d89538c9c")
    private String landingType;
    /**
     * 广告组时间戳,用于更新时提交,服务端判断是否基于最新信息修改
     */
    private String modifyTime;

    @Dict(dicCode = "item_value", dictTable = "sys_dict_item", dicText = "item_text",extendsKey = "dict_id",extendsValue = "fbc3e2fc9e6f5cfa5f6aeddd4c3bf818")
    private String status;
    /**
     * 广告组创建时间
     */
    private String campaignCreateTime;
    /**
     * 广告组修改时间
     */
    private String campaignModifyTime;
    /**
     * createTime
     */
    private Date createTime;
    /**
     * updateTime
     */
    private Date updateTime;

    @TableField(exist = false)
    private Boolean campaignStatus;

    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.name = name;
        this.budget = budget;
        this.budgetMode = budgetMode;
        this.landingType = landingType;
        this.modifyTime = modifyTime;
        this.status = status;
        this.campaignCreateTime = campaignCreateTime;
        this.campaignModifyTime = campaignModifyTime;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }

    public ByteDanceCampaign(JSONObject dataObject, Long accountId) {
        Long id = dataObject.getLong("id");
        this.id = id;
        this.accountId = accountId;
        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 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.accountId = oauthToken.getAccountId();
        this.name = campaignName;
        this.budgetMode = budgetMode;
        this.budget = BigDecimal.valueOf(budget);
        this.landingType = landingType;
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
    }
}
