package jnpf.model.personnels.dto.regular;

import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jnpf.model.cultivate.dto.offline.FtbCultivateOfflineFileDTO;
import jnpf.model.personnels.dto.base.FtbPersonnelsBaseForOA;
import jnpf.model.personnels.dto.salary.FtbPersonnelsSalaryInfo;
import jnpf.model.personnels.po.FtbPersonnelsRegularManagement;
import jnpf.model.personnels.po.FtbPersonnelsStaffRoster;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Title:FtbPersonnelsRegularCreateDTO
 * @Author:peng.hao
 * @create: 2024/2/119:50
 */
@Data
public class FtbPersonnelsRegularCreateDTO  extends FtbPersonnelsBaseForOA {

    private String id;

    /**
     * 1,手动转正 2,审批,3确认到岗
     */
    private String flag;
    /**
     * 手机号
     */
    private String phoneNumber;

    /**
     * 系统展示UserId
     */
    private String systemWokerId;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 用户姓名
     */
    private String userName;

    /**
     * 工号
     */
    @JsonIgnore
    private String jobNumber;

    /**
     * 入职日期
     */
    private Date dateOfEntry;

    /**
     * 试用期
     * 100	无试用期
     * 101	1个月内
     * 102	1个月
     * 103	2个月
     * 104	3个月
     * 105	4个月
     * 106	5个月
     * 107	6个月
     * 108	7个月
     * 109	8个月
     */
    private String probation;

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

    /**
     * 直属主管
     */
    private String immediateSuperId;

    /**
     * 直属主管name
     */
    private String immediateSuperName;
    /**
     * 计划转正日期
     */
    private Date schedConverDate;

    /**
     * 实际转正日期
     */
    private Date actualConverDate;


    /**
     * 所属组织id
     */
    private String orgId;

    /**
     * 所属组织名称
     */
    private String orgName;
    /**
     * 入职岗位id
     */
    @JsonIgnore
    private String onboardPostId;

    /**
     * 入职岗位名称
     */
    @JsonIgnore
    private String onboardPostName;

    /**
     * 入职职等id
     */
    @JsonIgnore
    private String onboardGradeId;

    /**
     * 职等name
     */
    @JsonIgnore
    private String onboardGradeName;
    /**
     * 班组id
     */
    private String teamID;
    /**
     * 班组名称
     */
    private String teamName;

    /**
     * 岗位id
     */
    private String regularPostId;

    /**
     * 岗位名称
     */
    private String regularPostName;

    /**
     * 职级id
     */
    private String regularGradeId;

    /**
     * 转正职级name
     */
    private String regularGradeName;

    /** 入职薪酬 */
    @Digits(integer = 8, fraction = 2, message = "金额的格式应为最多8位整数和2位小数")
    private BigDecimal startingSalary;

    /**
     * 转正薪酬
     */
    @Digits(integer = 8, fraction = 2, message = "金额的格式应为最多8位整数和2位小数")
    private BigDecimal regularSalary;


    /**
     * 申请来源 0,员工申请,1,审批办理,2直接办理,3确认到岗自动生成
     */
    private Integer source;

    /**
     * 附件信息上限10个
     */
    @Size(max = 10, message = "附件信息上限10个")
    @Valid
    private List<FtbCultivateOfflineFileDTO> files;

    private String filesWithOa;

    /**
     * 转正备注
     */
    @Length(max = 500, message = "转正备注长度不能超过500")
    private String remarksConver;

    /**
     * 是否调整薪酬(0,否,1是) (v1.1)
     */
    private String isAdjustSalary;


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

    /**
     * 薪资生效日期
     */
    private Date payrollEffectiveDate;

    /**
     *  薪资详情 (v1.1)
     */
    private List<FtbPersonnelsSalaryInfo> salaryStructureList;

    /**
     * 是否作废 0否 1是
     */
    private Integer isDelete;

    /**
     * 薪资调整原因
     */
    @JsonIgnore
    private String  reasonsForSalaryAdjustments;

    /**
     * 调薪方式 1.加薪 2.降薪
     */
    private Integer salaryType;


    /**
     * 薪资序列 id
     */
    private String payrollSequenceId;

    /**
     * 薪资序列
     *  1职级标准 2自定义标准
     */
    private Integer payrollSequence;


    /**
     * 薪资序列名称
     */
    private String payrollSequenceName;

    public static FtbPersonnelsRegularManagement coverFtbPersonnelsRegularManagement(FtbPersonnelsRegularCreateDTO createDTO) {
        if (createDTO == null) {
            return null;
        }
        FtbPersonnelsRegularManagement ftbPersonnelsRegularManagement = new FtbPersonnelsRegularManagement();
        ftbPersonnelsRegularManagement.setId(createDTO.getId());
        if (createDTO.getSpecialBusinessId() != null) ftbPersonnelsRegularManagement.setId(createDTO.getSpecialBusinessId());
        ftbPersonnelsRegularManagement.setPhoneNumber(createDTO.getPhoneNumber());
        ftbPersonnelsRegularManagement.setUserId(createDTO.getUserId());
        if (createDTO.getUserIds() != null && !createDTO.getUserIds().isEmpty()) ftbPersonnelsRegularManagement.setUserId(createDTO.getUserIds().get(0));
        ftbPersonnelsRegularManagement.setUserName(createDTO.getUserName());
        ftbPersonnelsRegularManagement.setJobNumber(createDTO.getJobNumber());
        ftbPersonnelsRegularManagement.setDateOfEntry(createDTO.getDateOfEntry());
        ftbPersonnelsRegularManagement.setProbation(createDTO.getProbation());
        ftbPersonnelsRegularManagement.setImmediateSuperId(createDTO.getImmediateSuperId());
        ftbPersonnelsRegularManagement.setImmediateSuperName(createDTO.getImmediateSuperName());
        ftbPersonnelsRegularManagement.setSchedConverDate(createDTO.getSchedConverDate());
        ftbPersonnelsRegularManagement.setActualConverDate(createDTO.getActualConverDate());
        ftbPersonnelsRegularManagement.setOrgId(createDTO.getOrgId());
        ftbPersonnelsRegularManagement.setOrgName(createDTO.getOrgName());
        ftbPersonnelsRegularManagement.setRegularPostId(createDTO.getRegularPostId());
        ftbPersonnelsRegularManagement.setRegularPostName(createDTO.getRegularPostName());
        ftbPersonnelsRegularManagement.setRegularGradeId(createDTO.getRegularGradeId());
        ftbPersonnelsRegularManagement.setRegularGradeName(createDTO.getRegularGradeName());
        ftbPersonnelsRegularManagement.setStartingSalary(createDTO.getStartingSalary());
        if(ObjectUtil.isEmpty(createDTO.getRegularSalary())){
            ftbPersonnelsRegularManagement.setRegularSalary(BigDecimal.ZERO);
        }else {
            ftbPersonnelsRegularManagement.setRegularSalary(createDTO.getRegularSalary());
        }
        ftbPersonnelsRegularManagement.setRemarksConver(createDTO.getRemarksConver());
        ftbPersonnelsRegularManagement.setProbationPeriodDay(createDTO.getProbationPeriodDay());
        ftbPersonnelsRegularManagement.setSystemWokerId(createDTO.getSystemWokerId());
        ftbPersonnelsRegularManagement.setIsAdjustSalary(createDTO.getIsAdjustSalary());
        ftbPersonnelsRegularManagement.setSalaryStructure(createDTO.getSalaryStructure());
        ftbPersonnelsRegularManagement.setOnboardPostId(createDTO.getOnboardPostId());
        ftbPersonnelsRegularManagement.setOnboardPostName(createDTO.getOnboardPostName());
        ftbPersonnelsRegularManagement.setOnboardGradeId(createDTO.getOnboardGradeId());
        ftbPersonnelsRegularManagement.setOnboardGradeName(createDTO.getOnboardGradeName());
        ftbPersonnelsRegularManagement.setPayrollEffectiveDate(createDTO.getActualConverDate());
        ftbPersonnelsRegularManagement.setReasonsForSalaryAdjustments(createDTO.getReasonsForSalaryAdjustments());
        ftbPersonnelsRegularManagement.setTeamID(createDTO.getTeamID());
        ftbPersonnelsRegularManagement.setTeamName(createDTO.getTeamName());
        ftbPersonnelsRegularManagement.setSalaryType(createDTO.getSalaryType());
        ftbPersonnelsRegularManagement.setPayrollSequenceId(createDTO.getPayrollSequenceId());
        ftbPersonnelsRegularManagement.setPayrollSequence(createDTO.getPayrollSequence());
        ftbPersonnelsRegularManagement.setPayrollSequenceName(createDTO.getPayrollSequenceName());
        return ftbPersonnelsRegularManagement;
    }

    public static FtbPersonnelsRegularCreateDTO coverFtbPersonnelsRegularInfoVO(FtbPersonnelsStaffRoster roster) {
        if (roster == null) {
            return null;
        }
        FtbPersonnelsRegularCreateDTO ftbPersonnelsRegularCreateDTO = new FtbPersonnelsRegularCreateDTO();
        ftbPersonnelsRegularCreateDTO.setId(roster.getId());
        ftbPersonnelsRegularCreateDTO.setUserId(roster.getUserId());
        ftbPersonnelsRegularCreateDTO.setSystemWokerId(roster.getSystemWokerId());
        ftbPersonnelsRegularCreateDTO.setJobNumber(roster.getWorkerNo());
        ftbPersonnelsRegularCreateDTO.setPhoneNumber(roster.getPhone());
        ftbPersonnelsRegularCreateDTO.setUserName(roster.getName());
        ftbPersonnelsRegularCreateDTO.setOrgId(roster.getCurrOrg());
        ftbPersonnelsRegularCreateDTO.setRegularPostId(roster.getCurrPosition());
        ftbPersonnelsRegularCreateDTO.setRegularGradeId(roster.getCurrRank());
        ftbPersonnelsRegularCreateDTO.setDateOfEntry(roster.getActualStartDate());
        if(ObjectUtil.isEmpty(roster.getRegularSalary())){
            ftbPersonnelsRegularCreateDTO.setRegularSalary(null);
        }else {
            ftbPersonnelsRegularCreateDTO.setRegularSalary(roster.getRegularSalary());
        }
        ftbPersonnelsRegularCreateDTO.setSource(3);
        ftbPersonnelsRegularCreateDTO.setFlag("3");
        ftbPersonnelsRegularCreateDTO.setOnboardPostId(roster.getCurrPosition());
        ftbPersonnelsRegularCreateDTO.setOnboardGradeId(roster.getCurrRank());

        return ftbPersonnelsRegularCreateDTO;
    }
}
