package com.storlead.sales.pojo.dto.excel;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.util.StrUtil;
import com.storlead.framework.annotate.Dict;
import com.storlead.framework.common.util.DateUtil;
import com.storlead.framework.common.validation.NotContains;
import com.storlead.sales.pojo.dto.customer.CustomerAddDTO;
import com.storlead.sales.pojo.dto.customer.CustomerCompanyAddDTO;
import com.storlead.sales.pojo.dto.customer.LiaisonAddDTO;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;


/** 客户
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-06-11 14:42
 */
@Data
public class CustomExcelVerifyEntity extends ExcelVerifyEntityOfMode  {

    @NotNull
    @Excel(name = "区域名称")
    private String areaName;

    @NotNull
    @Excel(name = "归属人员")
    private String ownerName;

    @NotNull
    @Excel(name = "归属人员账号")
    private String ownerAccount;

    @NotNull
    @Excel(name = "客户名称")
    private String customerName;

    @Excel(name = "企业网址")
    @NotNull
    @NotContains(value = "http", message = "网址不能包含 'http' 或者 'https'")
    private String website;

    private String intendedProductsIds;

    @Excel(name = "意向产品")
    @Dict(dictCode = "intended_products_type",keyField = "intendedProductsIds")
    private String intendedProductsNames;

    @Excel(name = "客户状态")
    @Dict(dictCode = "customer_status",keyField = "customerStatusDictValue")
    private String customerStatusName;

    private String customerStatusDictValue;

    @Excel(name = "客户来源")
    @Dict(dictCode = "customer_source",keyField = "customerSourceDictValue")
    private String customerSourceName;

    private String customerSourceDictValue;

    @Excel(name = "客户类型")
    @Dict(dictCode = "customer_type",keyField = "customerTypeDictValue")
    private String customerTypeDictName;

    private String customerTypeDictValue;

    @Excel(name = "代理合作")
    private String cooperativeCustomerName;

    private Long cooperativeCustomerId;

    @Excel(name = "客户等级")
    @Dict(dictCode = "customer_level",keyField = "customerLevelDictValue")
    private String customerLevelDictName;

    private String customerLevelDictValue;

    @Excel(name = "信用等级")
    @Dict(dictCode = "credit_rating",keyField = "customerCreditLevelDictValue")
    private String customerCreditLevelDictName;

    private String customerCreditLevelDictValue;

    @Excel(name = "经济性质")
    @Dict(dictCode = "economic_nature",keyField = "customerEconomicNatureDictValue")
    private String customerEconomicNatureDictName;

    private String customerEconomicNatureDictValue;

    @Excel(name = "助记名称")
    private String mnemonicName;

    @Excel(name = "备注信息")
    private String remark;

    /**
     * 联系人
     */
    @Excel(name = "首联系人人姓名")
    @NotNull
    private String lname;

    private Integer call;

    @Excel(name = "尊称")
    @Dict(dictCode = "call_dict_value",keyField = "call")
    private String callName;

    private String liaisonRoleDictValue;

    @Excel(name = "角色")
    @Dict(dictCode = "liaison_role",keyField = "liaisonRoleDictValue")
    private String liaisonRoleName;

    @Excel(name = "生日")
    private String birthdayStr;

    @Excel(name = "部门职务")
    private String departmentPosition;

    @Excel(name = "所在地区")
    private String internationalArea;

    @NotNull
    @Excel(name = "电子邮箱")
    private String lemail;

    @Excel(name = "Linkedin")
    private String linkedin;

    @Excel(name = "Facebook")
    private String facebook;

    @Excel(name = "Whatsapp")
    private String whatsapp;

    @Excel(name = "手机号码")
    private String ltelephone;

    @Excel(name = "Twitter")
    private String twitter;

    @Excel(name = "固定电话")
    private String fixedLineTelephone;

    @Excel(name = "传真号码")
    private String lfaxNumber;

    @Excel(name = "邮政编码")
    private String lpostcode;

    @Excel(name = "宅电")
    private String homeElectricity;

    @Excel(name = "QQ")
    private String qq;

    @Excel(name = "SKYPE")
    private String skype;

    @Excel(name = "旺旺")
    private String wangwang;

    @Excel(name = "微信")
    private String wechat;

    @Excel(name = "联系人备注信息")
    private String lremark;

    /**
     * 企业信息
     */
    private Long scaleDictValue;

    @Excel(name = "企业规模")
    @Dict(dictCode = "company_scale",keyField = "scaleDictValue")
    private String scaleName;

    @Excel(name = "所属行业")
    private String industry;

    @Excel(name = "通信地址")
    private String communicationAddress;

    @Excel(name = "企业邮政编码")
    private String postcode;

    @Excel(name = "企业传真号码")
    private String faxNumber;

    @Excel(name = "企业电子邮箱")
    private String email;

    @Excel(name = "联系电话")
    private String telephone;

    @Excel(name = "开户行")
    private String openingBank;

    @Excel(name = "税号")
    private String taxNumber;

    @Excel(name = "银行账号")
    private String bankAccount;

    public static CustomerAddDTO getCustomerAddDTO(CustomExcelVerifyEntity entity) {
        CustomerAddDTO dto = new CustomerAddDTO();
        BeanUtils.copyProperties(entity,dto);
        if (StrUtil.isNotBlank(entity.getAreaName())) {
            String [] areaNames = entity.getAreaName().split("/");
            if (Objects.nonNull(areaNames) && areaNames.length == 2) {
                dto.setContinent(areaNames[0]);
                dto.setCountry(areaNames[1]);

            }
        }
        CustomerCompanyAddDTO companyAddDTO = new CustomerCompanyAddDTO();
        BeanUtils.copyProperties(entity, companyAddDTO);
        dto.setCustomerCompany(companyAddDTO);


        LiaisonAddDTO liaisonAddDTO = new LiaisonAddDTO();
        BeanUtils.copyProperties(entity, liaisonAddDTO);
        liaisonAddDTO.setFaxNumber(entity.getLfaxNumber());
        liaisonAddDTO.setEmail(entity.getLemail());
        liaisonAddDTO.setPostcode(entity.getLpostcode());
        liaisonAddDTO.setRemark(entity.getLremark());
        liaisonAddDTO.setName(entity.getLname());
        liaisonAddDTO.setHasPrimaryLialison(true);
        if (StrUtil.isNotBlank(entity.getBirthdayStr())) {
            Date birthday = DateUtil.getDateByFormat(entity.getBirthdayStr(), "yyyy-MM-dd");
            liaisonAddDTO.setBirthday(birthday);
        }
        liaisonAddDTO.setEmail(entity.getLemail());
        dto.setLiaison(liaisonAddDTO);
        return dto;
    }
}
