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.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.Objects;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-06-27 16:50
 */
@Data
public class ClueExcelVerifyEntity 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
    private String name;


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


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

    private String customerSourceDictValue;

    @Excel(name = "线索状态")
    @Dict(dictCode = "clue_status",keyField = "clueStatusDictValue")
    private String clueStatusDictName;

    private String clueStatusDictValue;

    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 departmentPosition;

    @Excel(name = "详细地址")
    private String address;

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


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

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

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

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

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

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

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

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

    @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;

    public static CustomerAddDTO getCustomerAddDTO(ClueExcelVerifyEntity 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]);

            }
        }
        if (StrUtil.isNotBlank(entity.getWebsite())) {
            CustomerCompanyAddDTO companyAddDTO = new CustomerCompanyAddDTO();
            companyAddDTO.setWebsite(entity.getWebsite());
            dto.setCustomerCompany(companyAddDTO);
        }

        LiaisonAddDTO liaisonAddDTO = new LiaisonAddDTO();
        BeanUtils.copyProperties(entity, liaisonAddDTO);
        liaisonAddDTO.setHasPrimaryLialison(true);

        liaisonAddDTO.setEmail(entity.getEmail());

        dto.setLiaison(liaisonAddDTO);
        return dto;
    }
}
