package com.zcloud.basic.info.domain.model;

import com.jjb.saas.framework.domain.model.BaseE;
import com.zcloud.basic.info.domain.enums.UserChangeRecordStatusEnum;
import com.zcloud.basic.info.domain.enums.UserEmploymentFlagEnum;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * web-domain
 *
 * @Author zhaokai
 * @Date 2025-12-03 10:21:58
 */
@Data
public class UserCorpRecordE extends BaseE {
    //主键id
    private Long id;
    //业务主键id
    private String userCorpRecordId;
    //用户id
    private Long userId;
    //企业id
    private Long corpinfoId;
    //企业名称
    private String corpinfoName;
    //部门id
    private Long departmentId;
    //部门名称
    private String departmentName;
    //岗位id
    private Long postId;
    //岗位名称
    private String postName;
    //是否流动人员，1-流动，0-固定人员
    private Integer flowFlag;
    //审批状态，1-待审批, 2-通过,3-驳回
    private Integer status;
    //入职状态，1-在职 0-离职, 11-入职待审核, 10-离职待审核
    private Integer employmentFlag;
    //开始时间
    private LocalDateTime startTime;
    //结束时间
    private LocalDateTime endTime;
    private String resignationReason;
    //乐观锁
    private Integer version;
    //创建人
    private Long createId;
    //创建人姓名
    private String createName;
    //创建时间
    private LocalDateTime createTime;
    //更新人
    private Long updateId;
    //修改人名称
    private String updateName;
    //更新时间
    private LocalDateTime updateTime;
    //描述
    private String remarks;
    //是否删除
    private String deleteEnum;
    //租户ID
    private Long tenantId;
    //机构ID
    private Long orgId;
    //环境
    private String env;

    public void initAdd(UserE userE,String corpName,String departmentName) {
        this.userId = userE.getId();
        this.corpinfoId = userE.getCorpinfoId();
        this.corpinfoName = corpName;
        this.departmentId = userE.getDepartmentId();
        this.departmentName = departmentName;
        this.postId = userE.getPostId();
        this.postName = userE.getPostName();
        this.employmentFlag = UserEmploymentFlagEnum.ON.getCode();
        this.status = UserChangeRecordStatusEnum.APPROVED.getCode();
        this.startTime = LocalDateTime.now();
        this.flowFlag = userE.getFlowFlag();
    }

    public void initAddFromApp(UserE userE,String corpName,String departmentName) {
        this.userId = userE.getId();
        this.corpinfoId = userE.getCorpinfoId();
        this.corpinfoName = corpName;
        this.departmentId = userE.getDepartmentId();
        this.departmentName = departmentName;
        this.postId = userE.getPostId();
        this.postName = userE.getPostName();
        this.employmentFlag = UserEmploymentFlagEnum.NOT_ON.getCode();
        this.status = UserChangeRecordStatusEnum.PENDING.getCode();
        this.flowFlag = userE.getFlowFlag();
    }

    public void executeResignation(UserCorpRecordE userCorpRecordE, UserE userE,Integer employmentFlag,Integer  status) {
        this.corpinfoName = userCorpRecordE.getCorpinfoName();
        this.departmentId = userE.getDepartmentId();
        this.departmentName = userE.getDepartmentName();
        this.postId = userE.getPostId();
        this.postName = userE.getPostName();
        this.employmentFlag = employmentFlag;
        this.status = status;
        if(UserChangeRecordStatusEnum.APPROVED.getCode().equals( status)){
            this.endTime = LocalDateTime.now();
        }
    }

    public void initResignation(UserE userE,Integer employmentFlag,Integer  status) {
        this.userId = userE.getId();
        this.corpinfoId = userE.getCorpinfoId();
        this.corpinfoName = userE.getCorpinfoName();
        this.departmentId = userE.getDepartmentId();
        this.departmentName = userE.getDepartmentName();
        this.postId = userE.getPostId();
        this.postName = userE.getPostName();
        this.employmentFlag = employmentFlag;
        this.status = status;
        this.startTime = LocalDateTime.now();
        this.endTime = LocalDateTime.now();
        this.flowFlag = userE.getFlowFlag();
    }

    public void executeEntryAudit(UserCorpRecordE userCorpRecordE, UserE userE, Integer employmentFlag, Integer status) {
        this.userId = userE.getId();
        this.corpinfoId = userE.getCorpinfoId();
        this.corpinfoName = userCorpRecordE.getCorpinfoName();
        this.departmentId = userE.getDepartmentId();
        this.departmentName = userE.getDepartmentName();
        this.postId = userE.getPostId();
        this.postName = userE.getPostName();
        this.employmentFlag = employmentFlag;
        this.status = status;
    }
}

