package jnpf.model.personnels.dto.emp;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import jnpf.model.personnels.dto.salary.BaseSalaryStructureDTO;
import jnpf.model.personnels.po.FtbPersonnelsStaffEmploymentApply;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

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

/**
 * 办理入职DTO
 * @Author: peng.hao
 * @create: 2025/4/7
 */
@Data
public class FtbEmpConfirmDTO extends BaseSalaryStructureDTO {
    /**
     * 入职表ID
     */
    private String id;
    /**
     * 手机号码
     */
    private String phone;

    /**
     * 员工姓名
     */
    @NotBlank(message = "员工姓名不能为空")
    @Length(max = 20, message = "员工姓名不能超过20字")
    private String name;

    /**
     * 员工类型
     * 26	全职
     * 27	兼职日薪
     * 28	实习
     * 29	劳务派遣
     * 30	退休返聘
     * 31	劳务外包
     * 32   兼职小时工
     */
    @NotBlank(message = "员工类型不能为空")
    private String workerType;


    /**
     * 员工状态
     * 301、预入职  302、试用 303、正式  304、待离职  305 离职
     */
    @NotBlank(message = "员工状态不能为空")
    private String workerStatus;

    /**
     * 实际入职日期，格式为yyyy-MM-dd HH:mm:ss
     */
    @NotNull(message = "实际入职日期不能为空")
    private Date actualStartDate;


    /**
     * 试用期
     * 100	无试用期
     * 101	1个月内
     * 102	1个月
     * 103	2个月
     * 104	3个月
     * 105	4个月
     * 106	5个月
     * 107	6个月
     * 108	7个月
     * 109	8个月
     */
    @NotBlank(message = "试用期不能为空")
    private String probationPeriod;


    /**
     * 试用期天数，如果是1个月内，这里就是天数
     */
    private String probationPeriodDay;


    /**
     * 计划转正日期，格式为yyyy-MM-dd HH:mm:ss
     */
    @NotNull(message = "计划转正日期不能为空")
    private Date planProbationaryDate;

    /**
     * 入职组织
     */
    @NotBlank(message = "入职组织为空")
    private String currOrgId;

    /**
     * 入职岗位
     */
    @NotBlank(message = "入职岗位不能为空")
    private String currPositionId;

    /**
     * 班组
     */
    private String currShopId;

    /**
     * 入职职级
     */
    private String currRankId;
    /**
     * 入职备注
     */
    private String onboardingRemarks;
    /**
     * 上传入职附件
     */
    private String files;

    /**
     * 入职薪酬
     */
    @Digits(integer = 8, fraction = 2, message = "薪资项合计应为最多8位整数和2位小数")
    private BigDecimal entryMoney;
    /**
     * 直属主管
     */
    private String affiliatedReportsTo;

    /**
     * 入职次数
     */
    private Integer joinNum;


    public static FtbPersonnelsStaffEmploymentApply covertToEntity(FtbEmpConfirmDTO ftbEmpConfirmDTO) {
        FtbPersonnelsStaffEmploymentApply apply = new FtbPersonnelsStaffEmploymentApply();
        apply.setId(ftbEmpConfirmDTO.getId());
        apply.setPhone(ftbEmpConfirmDTO.getPhone());
        apply.setWorkerName(ftbEmpConfirmDTO.getName());
        // 后台办理
        apply.setSource(0);
        // 组织id
        apply.setCurrOrg(ftbEmpConfirmDTO.getCurrOrgId());
        // 岗位id
        apply.setCurrPosition(ftbEmpConfirmDTO.getCurrPositionId());
        // 职级id
        apply.setCurrRank(StringUtils.isNotEmpty(ftbEmpConfirmDTO.getCurrRankId()) ? ftbEmpConfirmDTO.getCurrRankId() : "");
        // 店铺id
        apply.setCurrGroupId(StringUtils.isNotEmpty(ftbEmpConfirmDTO.getCurrShopId()) ? ftbEmpConfirmDTO.getCurrShopId() : "");
        // 版本
        apply.setVersionNum(1);
        // 附件
        apply.setFiles(ftbEmpConfirmDTO.getFiles());
        // 备注
        apply.setOnboardingRemarks(ftbEmpConfirmDTO.getOnboardingRemarks());
        // 薪资结构
        apply.setPayrollSequence(ftbEmpConfirmDTO.getPayrollSequence());
        apply.setSalaryData(JSONArray.toJSONString(ftbEmpConfirmDTO.getSalaryList()));
        apply.setEntryMoney(ftbEmpConfirmDTO.getEntryMoney());
        apply.setTaskInfoId(ftbEmpConfirmDTO.getTaskId());
        apply.setActualStartDate(ftbEmpConfirmDTO.getActualStartDate());
        apply.setIsAdjustSalary(ftbEmpConfirmDTO.getIsAdjustSalary());
        apply.setPayrollSequenceId(ftbEmpConfirmDTO.getPayrollSequenceId());
        apply.setPlanProbationaryDate(ftbEmpConfirmDTO.getPlanProbationaryDate());
        apply.setPayrollSequenceName(ftbEmpConfirmDTO.getPayrollSequenceName());
        apply.setWorkerType(ftbEmpConfirmDTO.getWorkerType());
        apply.setWorkerStatus(ftbEmpConfirmDTO.getWorkerStatus());
        apply.setAffiliatedReportsTo(ftbEmpConfirmDTO.getAffiliatedReportsTo());
        apply.setProbationPeriod(ftbEmpConfirmDTO.getProbationPeriod());
        apply.setProbationPeriodDay(ftbEmpConfirmDTO.getProbationPeriodDay());
        return apply;
    }
}
