package com.ruoyi.info.collection.domain.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * 员工调动记录唯一键DTO
 * 用于唯一性校验：员工ID + 调动前部门ID + 调动后部门ID + 调动日期
 *
 * @author ruoyi
 * @date 2026-02-11
 */
@Data
@Schema(description = "员工调动记录唯一键")
public class TransferUniqueKey implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 员工ID
     */
    @Schema(description = "员工ID")
    private Long staffId;

    /**
     * 调动前部门ID
     */
    @Schema(description = "调动前部门ID")
    private Long deptIdBefore;

    /**
     * 调动后部门ID
     */
    @Schema(description = "调动后部门ID")
    private Long deptIdAfter;

    /**
     * 调动日期
     */
    @Schema(description = "调动日期")
    private Date transferDate;

    /**
     * 生成唯一标识字符串
     * 格式: staffId_deptIdBefore_deptIdAfter_transferDate的时间戳
     *
     * @return 唯一标识字符串
     */
    public String toUniqueString() {
        return staffId + "_" +
               deptIdBefore + "_" +
               deptIdAfter + "_" +
               (transferDate != null ? transferDate.getTime() : 0);
    }

    /**
     * 从AddDTO构建唯一键
     *
     * @param addDTO 新增DTO
     * @return 唯一键
     */
    public static TransferUniqueKey from(CcdiStaffTransferAddDTO addDTO) {
        TransferUniqueKey key = new TransferUniqueKey();
        key.setStaffId(addDTO.getStaffId());
        key.setDeptIdBefore(addDTO.getDeptIdBefore());
        key.setDeptIdAfter(addDTO.getDeptIdAfter());
        key.setTransferDate(addDTO.getTransferDate());
        return key;
    }

    /**
     * 从EditDTO构建唯一键
     *
     * @param editDTO 编辑DTO
     * @return 唯一键
     */
    public static TransferUniqueKey from(CcdiStaffTransferEditDTO editDTO) {
        TransferUniqueKey key = new TransferUniqueKey();
        key.setStaffId(editDTO.getStaffId());
        key.setDeptIdBefore(editDTO.getDeptIdBefore());
        key.setDeptIdAfter(editDTO.getDeptIdAfter());
        key.setTransferDate(editDTO.getTransferDate());
        return key;
    }
}
