package com.qqchen.deploy.backend.deploy.dto;

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

import java.time.LocalDateTime;

/**
 * 部署审批任务DTO
 * 
 * <p>结构化的审批任务信息，包含审批任务、部署记录、关联实体等信息
 * <p>用于部署审批列表，让审批人员快速了解审批内容
 *
 * @author qqchen
 * @since 2025-11-05
 */
@Data
@Schema(description = "部署审批任务信息")
public class DeployApprovalTaskDTO {

    // ========== 审批任务信息 ==========
    @Schema(description = "审批任务信息")
    private ApprovalTaskInfo approvalTask;

    // ========== 部署记录信息 ==========
    @Schema(description = "部署记录信息")
    private DeployRecordInfo deployRecord;

    // ========== 关联实体信息 ==========
    @Schema(description = "团队信息")
    private TeamInfo team;

    @Schema(description = "应用信息")
    private ApplicationInfo application;

    @Schema(description = "环境信息")
    private EnvironmentInfo environment;

    @Schema(description = "发起人信息")
    private UserSimpleInfo deployUser;

    // ========== 嵌套类定义 ==========

    /**
     * 审批任务信息
     */
    @Data
    @Schema(description = "审批任务信息")
    public static class ApprovalTaskInfo {
        
        @Schema(description = "任务ID")
        private String taskId;

        @Schema(description = "任务名称")
        private String taskName;

        @Schema(description = "任务描述")
        private String taskDescription;

        @Schema(description = "流程实例ID")
        private String processInstanceId;

        @Schema(description = "流程定义ID")
        private String processDefinitionId;

        @Schema(description = "审批人用户名")
        private String assignee;

        @Schema(description = "创建时间")
        private LocalDateTime createTime;

        @Schema(description = "到期时间")
        private LocalDateTime dueDate;

        @Schema(description = "待审批时长（毫秒）- 从任务创建到现在的时长")
        private Long pendingDuration;

        @Schema(description = "审批标题")
        private String approvalTitle;

        @Schema(description = "审批内容")
        private String approvalContent;

        @Schema(description = "审批模式: SINGLE-单人审批, MULTI-多人会签, OR-多人或签")
        private String approvalMode;

        @Schema(description = "是否允许转交")
        private Boolean allowDelegate;

        @Schema(description = "是否允许加签")
        private Boolean allowAddSign;

        @Schema(description = "是否必须填写意见")
        private Boolean requireComment;
    }

    /**
     * 部署记录信息
     */
    @Data
    @Schema(description = "部署记录信息")
    public static class DeployRecordInfo {
        
        @Schema(description = "部署记录ID")
        private Long id;

        @Schema(description = "业务标识（UUID）")
        private String businessKey;

        @Schema(description = "部署备注")
        private String remark;

        @Schema(description = "部署开始时间")
        private LocalDateTime startTime;
    }

    /**
     * 团队信息
     */
    @Data
    @Schema(description = "团队信息")
    public static class TeamInfo {
        
        @Schema(description = "团队ID")
        private Long id;

        @Schema(description = "团队名称")
        private String name;
    }

    /**
     * 应用信息
     */
    @Data
    @Schema(description = "应用信息")
    public static class ApplicationInfo {
        
        @Schema(description = "应用ID")
        private Long id;

        @Schema(description = "应用编码")
        private String code;

        @Schema(description = "应用名称")
        private String name;
    }

    /**
     * 环境信息
     */
    @Data
    @Schema(description = "环境信息")
    public static class EnvironmentInfo {
        
        @Schema(description = "环境ID")
        private Long id;

        @Schema(description = "环境编码")
        private String code;

        @Schema(description = "环境名称")
        private String name;
    }

    /**
     * 用户简要信息
     */
    @Data
    @Schema(description = "用户简要信息")
    public static class UserSimpleInfo {
        
        @Schema(description = "用户名")
        private String username;

        @Schema(description = "昵称")
        private String nickname;

        @Schema(description = "邮箱")
        private String email;

        @Schema(description = "手机号")
        private String phone;

        @Schema(description = "部门名称")
        private String departmentName;
    }
}

