package com.ruoyi.project.business.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 【请填写功能名称】对象 tb_agent
 *
 * @author ruoyi
 * @date 2024-04-16
 */

@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName("tb_agent")
public class TbAgent extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 代理商ID
     */
    @TableId(type = IdType.AUTO)
    private Long agentId;

    /**
     * 代理商编号
     */
    @Excel(name = "代理商编号", i18nCode = "agent.agentNo")
    private String agentNo;

    /**
     * 代理商名称
     */
    @Excel(name = "代理商名称", i18nCode = "agent.agentName")
    private String agentName;

    /**
     * 代理商类型（关联字典表） 1:1级；2:2级；
     */
    @Excel(name = "代理商类型", dictType = "agent_type", i18nCode = "agent.agentType")
    private String agentType;

    /**
     * 是否签约(0:false;1:true)
     */
    @Excel(name = "是否签约", dictType = "yes_no_tinyint", i18nCode = "agent.hasContract")
    private Integer hasContract;

    /**
     * 所属区域
     */
    private Long areaId;

    /**
     * 所在国家 07-24:改为多选
     */
    private String countryId;


    @TableField(exist = false)
    private List<Long> countryIds;

    public List<Long> getCountryIds() {
        if (CollectionUtils.isEmpty(countryIds) && countryId != null) {
            countryIds = Arrays.stream(countryId.split(","))
                    .map(Long::parseLong)
                    .collect(Collectors.toList());
        }
        return countryIds;
    }

    public void setCountryIds(List<Long> countryIds) {
        this.countryIds = countryIds;
        if (countryIds != null && !countryIds.isEmpty()) {
            this.countryId = countryIds.stream()
                    .map(Object::toString)
                    .collect(Collectors.joining(","));
        } else {
            this.countryId = null;
        }
    }

    /**
     * 代理商可用国家列表
     */
    @TableField(exist = false)
    private List<TbCountry> countryList;

    /**
     * 上级代理，没有则为0
     */
    private Long parentAgentId;

    /**
     * 上级销售ID userId
     */
    private Long parentSalerId;

    /**
     * 代理商等级（关联字典表）
     */
    @Excel(name = "代理商等级", dictType = "agent_level", i18nCode = "agent.agentLevel")
    private String agentLevel;

    private Boolean discountFlag;

    /**
     * 折扣率
     */
    @Excel(name = "折扣率(%)", i18nCode = "country.discount")
    private BigDecimal discount;

    private String discountType;
    private String discountFormula;
    private String discountFormulaTxt;

    /**
     * 负责人名称
     */
    @Excel(name = "负责人名称", i18nCode = "agent.head")
    private String head;

    /**
     * 联系方式
     */
    @Excel(name = "联系方式", i18nCode = "agent.phone")
    private String phone;

    /**
     * 邮箱
     */
    @Excel(name = "邮箱", i18nCode = "agent.email")
    private String email;

    /**
     * 地址
     */
    @Excel(name = "地址", i18nCode = "agent.address")
    private String address;

    /**
     * 状态（0：启用  1：停用）
     */
    @Excel(name = "状态", readConverterExp = "0=启用,1=停用", i18nCode = "agent.status")
    private String status;

    /**
     * 数据权限字符
     */
    private String permissionChar;

    /**
     * 删除标记（0：启用  1：停用）
     */
    @TableLogic
    private String delFlag;

    /**
     * 父级名称
     */
    @Excel(name = "上级代理", i18nCode = "agent.parentAgent")
    @TableField(exist = false)
    private String parentAgentName;

    /**
     * 上级销售名称
     */
    @Excel(name = "上级销售", i18nCode = "agent.parentSaler")
    @TableField(exist = false)
    private String parentSalerName;

    /**
     * 地区name
     */
    @Excel(name = "所属区域", i18nCode = "agent.areaId")
    @TableField(exist = false)
    private String areaName;

    /**
     * 国家name
     * TODO 可以使用 自定义数据处理器 处理，但是导出数据量大、或者对应字典数据量大时，会导致性能问题
     */
    @Excel(name = "所在国家", i18nCode = "agent.countryId")
    @TableField(exist = false)
    private String countryName;
    
    /**
     * 城市
     */
    @Excel(name = "城市", i18nCode = "project.city")
    private String city;

    /**
     * 首次合作年份
     */
    @Excel(name = "首次合作年份", i18nCode = "agent.firstCooperationYear")
    private String firstCooperationYear;


    // 0725新增 start
    /**
     * 协议生效日期 protocol_start_date
     */
    @Excel(name = "协议生效日期", i18nCode = "agent.protocolStartDate", dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date protocolStartDate;

    /**
     * 协议失效日期 protocol_end_date
     */
    @Excel(name = "协议失效日期", i18nCode = "agent.protocolEndDate", dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date protocolEndDate;

    /**
     * 授权区域 authorized_area
     */
    @Excel(name = "授权区域", i18nCode = "agent.authorizedArea")
    private String authorizedArea;

    // 0725新增 end

    /**
     * 多选区域
     */
    @TableField(exist = false)
    private List<String> areaIds;

    /**
     * 多选代理商等级
     */
    @TableField(exist = false)
    private List<String> agentLevels;

    /**
     * 本年度考核信息
     */
    @TableField(exist = false)
    private TbAgentTarget agentTarget;

    @TableField(exist = false)
    private List<String> agentIds;
    
    @TableField(exist = false)
    private String curUserPermissionChar;

    /**
     * 来源
     */
    private String origin;

    @TableField(exist = false)
    private List<String> origins;
    
    /**
     * 附件
     */
    @TableField(exist = false)
    private String annex;


    /**
     * isThisYear 是否是今年
     */
    @TableField(exist = false)
    private Boolean isThisYear;
    
    /**
     * 协议生效日期:列表检索开始
     */
    @TableField(exist = false)
    private Date protocolSsDate;
    /**
     * 协议生效日期:列表检索结束
     */
    @TableField(exist = false)
    private Date protocolSeDate;
    /**
     * 协议失效日期:列表检索开始
     */
    @TableField(exist = false)
    private Date protocolEsDate;
    /**
     * 协议失效日期:列表检索结束
     */
    @TableField(exist = false)
    private Date protocolEeDate;
    @TableField(exist = false)
    private int configValue;
}
