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

import com.njcn.rdms.module.project.dal.dataobject.attachment.AttachmentItem;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;

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

/**
 * 任务工时新增/更新请求。同表共用：updateWorklog 不接受 taskId / userId 切换，前端无需也无法传。
 * 段语义：startDate / endDate 必填，单天 = 二者相等；同人同任务下日期范围禁止重叠（Service 层校验）。
 * 颗粒：durationHours 必须 > 0 且为 0.5 的整数倍（Service 层校验）。
 */
@Schema(description = "管理后台 - 任务工时 Save Request VO")
@Data
public class TaskWorklogSaveReqVO {

    @Schema(description = "段起始日期（含），单天=与 endDate 相等",
            requiredMode = Schema.RequiredMode.REQUIRED, example = "2026-05-04")
    @NotNull(message = "段起始日期不能为空")
    private LocalDate startDate;

    @Schema(description = "段结束日期（含），单天=与 startDate 相等",
            requiredMode = Schema.RequiredMode.REQUIRED, example = "2026-05-08")
    @NotNull(message = "段结束日期不能为空")
    private LocalDate endDate;

    @Schema(description = "本次填报小时数，> 0 且必须为 0.5 的整数倍",
            requiredMode = Schema.RequiredMode.REQUIRED, example = "8.0")
    @NotNull(message = "工时小时数不能为空")
    @DecimalMin(value = "0.5", message = "工时小时数必须大于 0 且为 0.5 的整数倍")
    private BigDecimal durationHours;

    @Schema(description = "本次填报进度（0~100，必填）。owner 填报：以 owner 本人最新一条工时（按 end_date 排序）"
            + "为准同步任务进度；协作人填报：仅作为本人自评个人完成度，不影响任务/父任务进度",
            requiredMode = Schema.RequiredMode.REQUIRED, example = "60.00")
    @NotNull(message = "本次填报进度不能为空")
    @DecimalMin(value = "0.00", message = "本次填报进度不能小于 0")
    @DecimalMax(value = "100.00", message = "本次填报进度不能大于 100")
    private BigDecimal progressRate;

    @Schema(description = "完成难度字典 rdms_worklog_difficulty 值，1=简单 / 2=一般 / 3=困难 / 4=超难",
            requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @NotBlank(message = "完成难度不能为空")
    @Size(max = 8, message = "完成难度长度不能超过 8 个字符")
    private String difficulty;

    @Schema(description = "工作内容描述", example = "完成接口联调与冒烟测试")
    @Size(max = 2000, message = "工作内容长度不能超过 2000 个字符")
    private String workContent;

    @Schema(description = "附件列表；规则与限制详见 AttachmentValidator（数量上限、扩展名白/黑名单、URL 协议）")
    @Valid
    private List<AttachmentItem> attachments;
}
