package jnpf.model.personnels.dto.apply;

import cn.hutool.core.collection.CollUtil;
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.FtbPersonnelsPostApply;
import lombok.Data;

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

/**
 * @Title: FtbPersonnelsApplyCreateDto
 * @Author: peng.hao
 * @create: 2023/12/2515:50
 */
@Data
public class FtbPersonnelsApplyCreateDto extends FtbPersonnelsBaseForOA {
    /**
     * 重新办理主键id
     */
    private String id;

    /**
     * 1,手动转正 2,审批
     */
    private String flag;
    /**
     * 当前岗位id
     */
    @NotNull(message = "当前岗位id,不能为空")
    private String postId;

    /**
     * 当前岗位名称
     */
    private String postName;

    /**
     *
     * 工号
     */
    private String jobNumber;
    /**
     * 手机号
     */
    private String phoneNumber;
    /**
     * 用户id
     */
    private String userId;
    /**
     * 系统展示用户id
     */
    private String systemWokerId;
    /**
     * 用户名词
     */
    private String userName;

    /**
     * 晋升原因
     */
    private String promotionReason;


    /**
     * 当前岗位职等id
     */
    private String postRankId;

    /**
     * 当前岗位职等名称
     */
    private String postRankName;
    /**
     * 晋升岗位id
     */
    @NotNull(message = "晋升岗位id,不能为空")
    private String postPromotionId;

    /**
     * 晋升岗位名称
     */
    private String postPromotionName;


    /**
     * 晋升岗位职等id
     */
    @NotNull(message = "晋升岗位职等id,不能为空")
    private String postRankPromotionId;
    /**
     * 晋升岗位职等名称
     */
    private String postRankPromotionName;

    /**
     * 组织主键id
     */
    @NotNull(message = "组织主键id,不能为空")
    private String orgId;

    /**
     * 组织主键名称
     */
    private String orgName;

    /**
     * 当前晋升组织主键id
     */
    private String orgCurrentId;

    /**
     * 组织主键名称
     */
    private String orgCurrentName;
    /**
     * 附件信息上限10个
     */
    @Size(max = 10, message = "附件信息上限10个")
    @Valid
    private List<FtbCultivateOfflineFileDTO> files;

    private String filesWithOa;

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

    /**
     * 晋升后薪酬
     */
    @Digits(integer = 12, fraction = 2, message = "金额的格式应为最多12位整数和2位小数")
    private BigDecimal postPromotionPay;
    /**
     * 0,员工申请,1,审批办理,2直接办理
     */
    private Integer source;
    /**
     * 直属主管
     */
    private String immediateSuperId;
    /**
     * 直属主管name
     */
    private String immediateSuperName;

    /**
     * 旧直属主管
     */
    private String OldImmediateSuperId;
    /**
     * 旧直属主管name
     */
    private String OldImmediateSuperName;

    /**
     * 考情组id
     */
    private String attendanceGroup;


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

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


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


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

    /**
     * 当前晋升角色id (v1.1) 多个已,号分割
     */
    private String roleId;

    /**
     * 晋升角色，多个角色逗号分开
     */
    private List<String> roleIds;

    /**
     * 当前晋升角色名称 (v1.1)
     */
    private String roleName;
    /**
     * 是否作废薪酬 0 , 1
     */
    private Integer isDelete;

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


    public static FtbPersonnelsPostApply coverFtbPersonnelsApplyVO(FtbPersonnelsApplyCreateDto createDto) {
        if (createDto == null) {
            return null;
        }
        FtbPersonnelsPostApply ftbPersonnelsPostApply = new FtbPersonnelsPostApply();
        ftbPersonnelsPostApply.setPostId(createDto.getPostId());
        ftbPersonnelsPostApply.setPostName(createDto.getPostName());
        ftbPersonnelsPostApply.setJobNumber(createDto.getJobNumber());
        ftbPersonnelsPostApply.setPhoneNumber(createDto.getPhoneNumber());
        ftbPersonnelsPostApply.setUserId(createDto.getUserId());
        if(createDto.getUserIds() !=null && !createDto.getUserIds().isEmpty()) ftbPersonnelsPostApply.setUserId(createDto.getUserIds().get(0));
        ftbPersonnelsPostApply.setUserName(createDto.getUserName());
        ftbPersonnelsPostApply.setPromotionReason(createDto.getPromotionReason());
        ftbPersonnelsPostApply.setPostRankId(createDto.getPostRankId());
        ftbPersonnelsPostApply.setPostRankName(createDto.getPostRankName());
        ftbPersonnelsPostApply.setPostPromotionId(createDto.getPostPromotionId());
        ftbPersonnelsPostApply.setPostPromotionName(createDto.getPostPromotionName());
        ftbPersonnelsPostApply.setPostRankPromotionId(createDto.getPostRankPromotionId());
        ftbPersonnelsPostApply.setPostRankPromotionName(createDto.getPostRankPromotionName());
        ftbPersonnelsPostApply.setOrgId(createDto.getOrgId());
        ftbPersonnelsPostApply.setOrgName(createDto.getOrgName());
        ftbPersonnelsPostApply.setOrgCurrentId(createDto.getOrgCurrentId());
        ftbPersonnelsPostApply.setOrgCurrentName(createDto.getOrgCurrentName());
        ftbPersonnelsPostApply.setCurrentPay(createDto.getCurrentPay());
        ftbPersonnelsPostApply.setPostPromotionPay(createDto.getPostPromotionPay());
        ftbPersonnelsPostApply.setSource(createDto.getSource());
        ftbPersonnelsPostApply.setSystemWokerId(createDto.getSystemWokerId());
        ftbPersonnelsPostApply.setImmediateSuperId(createDto.getImmediateSuperId());
        ftbPersonnelsPostApply.setImmediateSuperName(createDto.getImmediateSuperName());
        ftbPersonnelsPostApply.setOldImmediateSuperId(createDto.getOldImmediateSuperId());
        ftbPersonnelsPostApply.setOldImmediateSuperName(createDto.getOldImmediateSuperName());
        ftbPersonnelsPostApply.setAttendanceGroup(createDto.getAttendanceGroup());
        ftbPersonnelsPostApply.setRoleId(createDto.getRoleId());
        ftbPersonnelsPostApply.setRoleName(createDto.getRoleName());
        ftbPersonnelsPostApply.setSalaryStructure(createDto.getSalaryStructure());
        ftbPersonnelsPostApply.setIsAdjustSalary(createDto.getIsAdjustSalary());
        ftbPersonnelsPostApply.setPayrollEffectiveDate(createDto.getPayrollEffectiveDate());
        if (CollUtil.isNotEmpty(createDto.getRoleIds())) ftbPersonnelsPostApply.setRoleId(createDto.getRoleIds().stream().collect(Collectors.joining(",")));
        ftbPersonnelsPostApply.setReasonsForSalaryAdjustments(createDto.getReasonsForSalaryAdjustments());
        return ftbPersonnelsPostApply;
    }

}
