package com.ruoyi.ibs.grid.domain.excel;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ibs.enumertion.CustTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Objects;
import java.util.regex.Pattern;

/**
 * @Author 吴凯程
 * @Date 2024/9/23
 **/
@Data
public class VirtualCustImportDTO {


    @ApiModelProperty(value = "客户类型", name = "custType", notes = "个人 企业 商户")
    @Excel(name = "客户类型(个人 企业 商户)*", prompt = "必填", combo = "个人,商户,企业")
    private String custType;

    @ApiModelProperty(value = "客户号", name = "custId")
    @Excel(name = "客户号*", prompt = "必填")
    private String custId;

    @ApiModelProperty(value = "客户姓名", name = "custName")
    @Excel(name = "客户姓名")
    private String custName;

    @ApiModelProperty(value = "客户证件类型(身份证 营业执照)", name = "custIdType")
    private String custIdType;

    @ApiModelProperty(value = "客户证件号", name = "custIdn")
    @Excel(name = "客户证件号")
    private String custIdn;

    @ApiModelProperty(value = "客户内码", name = "custIsn")
    @Excel(name = "客户内码")
    private String custIsn;

    @ApiModelProperty(value = "电话号码", name = "phoneNum")
    @Excel(name = "电话号码")
    private String phoneNum;

    public void checkValid() {
        if (!StringUtils.isNotEmpty(custType) || !StringUtils.isNotEmpty(custId)) {
            throw new ServiceException("缺少必填项！");
        }

        if(!Pattern.matches("[a-zA-Z0-9]+",custId)){
            throw new ServiceException("客户号不能包含除数字字母以外的其他字符！");
        }


        if (Objects.isNull(CustTypeEnum.getByName(custType))) {
            throw new ServiceException("客户类型错误！");
        }

//        if (StringUtils.isNotEmpty(custIdType) && Objects.isNull(CustIdTypeEnum.getByName(custIdType))) {
//            throw new ServiceException("客户证件类型错误！");
//        }
    }
}
