package com.njcn.rdms.module.project.controller.admin.project.task.vo;

import com.njcn.rdms.module.project.dal.dataobject.attachment.AttachmentItem;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;



@Schema(description = "管理后台 - 任务 Response VO")
@Data
public class ProjectTaskRespVO {

    @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "9001")
    private Long id;
    @Schema(description = "所属项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2001")
    private Long projectId;
    @Schema(description = "所属执行编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5001")
    private Long executionId;
    @Schema(description = "所属执行名称", example = "迭代 V1.0")
    private String executionName;
    @Schema(description = "所属执行状态码")
    private String executionStatusCode;
    @Schema(description = "所属执行关联的项目需求编号（service 层批量回填）")
    private Long projectRequirementId;
    @Schema(description = "项目需求名称（service 层批量回填，避免 N+1）", example = "前端联调-需求A")
    private String projectRequirementName;
    @Schema(description = "项目需求状态编码（service 层批量回填）", example = "implementing")
    private String projectRequirementStatusCode;
    @Schema(description = "父任务编号")
    private Long parentTaskId;
    @Schema(description = "父任务负责人用户编号；一级任务为 null，子任务用于前端判断"
            + "新增子任务/编辑/删除按钮显隐（详见前端联调清单 §4.3）", example = "3002")
    private Long parentTaskOwnerId;
    @Schema(description = "所属执行的负责人用户编号；前端判断一级任务"
            + "新增/编辑/删除按钮显隐（一级任务执行负责人可自行调整）", example = "3001")
    private Long executionOwnerId;
    @Schema(description = "任务标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "接口联调任务")
    private String taskTitle;
    @Schema(description = "任务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "feature")
    private String type;
    @Schema(description = "任务负责人用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3002")
    private Long ownerId;
    @Schema(description = "任务负责人昵称", example = "李四")
    private String ownerNickname;
    @Schema(description = "任务状态编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "pending")
    private String statusCode;
    @Schema(description = "任务状态名称", example = "待开始")
    private String statusName;
    @Schema(description = "优先级编码（字典 rdms_req_priority），0=P0(最高) ~ 3=P3(最低)", example = "0")
    private String priority;
    @Schema(description = "优先级名称（字典 label，后端不填、前端按字典 cache 自译）", example = "P0")
    private String priorityName;
    @Schema(description = "是否终态", example = "false")
    private Boolean terminal;
    @Schema(description = "当前状态是否允许编辑", example = "true")
    private Boolean allowEdit;
    @Schema(description = "当前状态可执行动作")
    private List<ProjectTaskLifecycleActionRespVO> availableActions;
    @Schema(description = "任务进度")
    private BigDecimal progressRate;
    @Schema(description = "计划开始日期")
    private LocalDate plannedStartDate;
    @Schema(description = "计划结束日期")
    private LocalDate plannedEndDate;
    @Schema(description = "实际开始日期")
    private LocalDate actualStartDate;
    @Schema(description = "实际结束日期")
    private LocalDate actualEndDate;
    @Schema(description = "任务说明")
    private String taskDesc;
    @Schema(description = "最近一次状态动作原因")
    private String lastStatusReason;
    @Schema(description = "当前活跃协办人列表；详细变更历史见 assignee-logs 接口")
    private List<TaskAssigneeView> assignees;
    @Schema(description = "已填报工时合计（小时，0.5 颗粒）；逻辑删除的工时记录不计入。无记录默认为 0",
            example = "8.0")
    private BigDecimal totalSpentHours;
    @Schema(description = "附件列表")
    private List<AttachmentItem> attachments;
    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime createTime;
    @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime updateTime;

    @Schema(description = "任务协办人轻量视图")
    @Data
    public static class TaskAssigneeView {
        @Schema(description = "协办关系编号", example = "7001")
        private Long id;
        @Schema(description = "协办人用户编号", example = "3002")
        private Long userId;
        @Schema(description = "协办人昵称", example = "张三")
        private String nickname;
    }

}
