package jnpf.model.personnels.req.employment;

import cn.hutool.core.lang.RegexPool;
import jnpf.model.personnels.dto.base.FtbPersonnelsBaseForOA;
import jnpf.model.personnels.dto.salary.FtbPersonnelsSalaryInfo;
import jnpf.model.personnels.vo.employment.AddStaffEmploymentApplyExcelVO;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 办理入职请求对象
 */
@Data
public class AddStaffEmploymentApplyReq extends FtbPersonnelsBaseForOA {

    /**
     * 手机号码
     */
    @Length(min = 11, max = 11, message = "手机号码长度不能超过11位")
    @Pattern(regexp = RegexPool.MOBILE, message = "手机号码格式不正确")
    private String phone;

    /**
     * 姓名
     */
    @Length(max = 20, message = "姓名不能超过20字")
    private String workerName;

    /**
     * 组织id
     */
    @NotNull(message = "组织不能为空")
    private String currOrg;

    /**
     * 岗位id
     */
    @NotNull(message = "岗位不能为空")
    private String currPosition;

    /**
     * 职等id
     */
    @NotNull(message = "职等不能为空")
    private String currRank;


    /**
     * 合同类型ID
     */
    private String contractType;


    /**
     * 预计入职日期
     */
    @NotNull(message = "期望日期不能为空")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date expectedStartDate;

    /**
     * 来源关联ID,内推人ID 或者 内推组织id 或者 内推门店id
     */
    private String sourceRelationId;

    /**
     * 来源，0、后台办理 1、APP端个人内推  2、门店招聘、3、组织招聘
     */
    private Integer source;


    /**
     * 入职薪酬
     */
    @Digits(integer = 12, fraction = 2, message = "金额超过限制")
    private BigDecimal entryMoney;

    /**
     * 是否需要审批：0、需要审批  1、不需要审批
     */
    private Integer isNeedCheck;

    /**
     * 入职备注
     */
    @Length(min = 0, max = 1000, message = "入职备注长度不能超过1000个字符")
    private String onboardingRemarks;

    /**
     * 考勤组
     */
    private String attendanceGroup;

    /**
     * 考勤组
     */
    private String attendanceGroupName;

    /**
     * 附件，格式：[{name:"",url:"",fileSize:"",fileExtension:""}]
     */
    private String files;

    /**
     * 薪资结构(0,不使用,1使用)
     */
    private String salaryStructure;

    /**
     * 薪酬项列表
     */
    private List<FtbPersonnelsSalaryInfo> salaryItemList;

    /**
     * 薪酬总额
     */
    @Digits(integer = 12, fraction = 2, message = "金额超过限制")
    private BigDecimal salaryTotalAmount;

    /**
     * 照片
     */
    private String photoFiles;

    public static AddStaffEmploymentApplyReq convert(AddStaffEmploymentApplyExcelVO vo) {
        if (vo == null) {
            return null;
        }
        AddStaffEmploymentApplyReq addStaffEmploymentApplyReq = new AddStaffEmploymentApplyReq();
        addStaffEmploymentApplyReq.setWorkerName(vo.getWorkerName());
        addStaffEmploymentApplyReq.setPhone(vo.getPhone());
        addStaffEmploymentApplyReq.setCurrOrg(vo.getCurrOrgId());
        addStaffEmploymentApplyReq.setContractType(vo.getContractType());
        addStaffEmploymentApplyReq.setExpectedStartDate(vo.getExpectedStartDate());
        addStaffEmploymentApplyReq.setCurrPosition(vo.getCurrPositionId());
        addStaffEmploymentApplyReq.setCurrRank(vo.getCurrRankId());
        addStaffEmploymentApplyReq.setEntryMoney(BigDecimal.ZERO);
        addStaffEmploymentApplyReq.setAttendanceGroupName(vo.getAttendanceGroupName());
        return addStaffEmploymentApplyReq;
    }

}
