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.sales.pojo.dto.customer.LiaisonAddDTO;
import com.storlead.sales.pojo.entity.customer.LiaisonEntity;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-06-28 16:18
 */
@Data
public class LiaisonExcelVerifyEntity extends ExcelVerifyEntityOfMode {

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

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

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

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

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

    public static <T extends ExcelVerifyEntityOfMode> LiaisonAddDTO getLiaisonAddDTO(LiaisonExcelVerifyEntity entity) {
        LiaisonAddDTO liaisonAddDTO = new LiaisonAddDTO();
        BeanUtils.copyProperties(entity, liaisonAddDTO);
        if (StrUtil.isNotBlank(entity.getBirthdayStr())) {
            Date birthday = DateUtil.getDateByFormat(entity.getBirthdayStr(), "yyyy-MM-dd");
            liaisonAddDTO.setBirthday(birthday);
        }
        liaisonAddDTO.setEmail(entity.getEmail());
        return liaisonAddDTO;
    }

    public static List<LiaisonEntity> assembleLiaisonLs(List<LiaisonAddDTO> dtos) {
        List<LiaisonEntity> liaisons = new ArrayList<>();
        for (LiaisonAddDTO dto : dtos) {
            LiaisonEntity latest = new LiaisonEntity();
            BeanUtils.copyProperties(dto, latest);
            latest.setHasPrimaryLialison(false);
            latest.setEmail(dto.getEmail());
            liaisons.add(latest);
        }
        return liaisons;
    }
    public static LiaisonEntity assembleLiaison(LiaisonAddDTO dto) {
        LiaisonEntity latest = new LiaisonEntity();
        BeanUtils.copyProperties(dto, latest);
        latest.setHasPrimaryLialison(false);
        latest.setEmail(dto.getEmail());
        return latest;
    }
}
