package com.dora.dto;

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

import jakarta.validation.constraints.NotBlank;
import java.time.LocalDateTime;

/**
 * 广场作品审核相关DTO
 */
public class AdminPlazaAuditDto {

    private AdminPlazaAuditDto() {
        // 私有构造函数，防止实例化
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "审核作品请求")
    public static class AuditWorkRequest {
        @NotBlank(message = "作品编号不能为空")
        @Schema(description = "作品编号", example = "WORK-20251026183750127-8554")
        private String workNo;

        @NotBlank(message = "审核结果不能为空")
        @Schema(description = "审核结果：approved-通过, rejected-拒绝", example = "approved", allowableValues = {"approved", "rejected"})
        private String auditStatus;

        @Schema(description = "审核备注（拒绝时必填）", example = "内容违规")
        private String auditRemark;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "待审核作品列表请求")
    public static class PendingWorksQueryRequest {
        @Builder.Default
        @Schema(description = "页码", example = "1")
        private Integer page = 1;

        @Builder.Default
        @Schema(description = "每页数量", example = "20")
        private Integer size = 20;

        @Schema(description = "任务类型筛选", example = "text_to_image")
        private String taskType;

        @Schema(description = "用户ID筛选", example = "17563793187762127")
        private Long userId;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "待审核作品详情响应")
    public static class PendingWorkDetailResponse {
        @Schema(description = "作品编号")
        private String workNo;

        @Schema(description = "作品标题")
        private String title;

        @Schema(description = "作品描述")
        private String description;

        @Schema(description = "作品封面URL")
        private String coverUrl;

        @Schema(description = "作品结果URL")
        private String resultUrl;

        @Schema(description = "任务类型")
        private String taskType;

        @Schema(description = "模型名称")
        private String modelName;

        @Schema(description = "提示词")
        private String prompt;

        @Schema(description = "发布时间")
        private LocalDateTime createTime;

        @Schema(description = "作者信息")
        private AuthorInfo author;

        @Schema(description = "关联任务编号")
        private String taskNo;

        @Data
        @Builder
        @NoArgsConstructor
        @AllArgsConstructor
        @Schema(description = "作者信息")
        public static class AuthorInfo {
            @Schema(description = "用户ID")
            private Long userId;

            @Schema(description = "用户名")
            private String username;

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

            @Schema(description = "头像URL")
            private String avatarUrl;
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "待审核作品列表响应")
    public static class PendingWorksListResponse {
        @Schema(description = "作品列表")
        private java.util.List<PendingWorkDetailResponse> works;

        @Schema(description = "总记录数")
        private Long total;

        @Schema(description = "当前页码")
        private Integer page;

        @Schema(description = "每页数量")
        private Integer size;

        @Schema(description = "总页数")
        private Integer totalPages;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "审核结果响应")
    public static class AuditResultResponse {
        @Schema(description = "作品编号")
        private String workNo;

        @Schema(description = "审核状态")
        private String auditStatus;

        @Schema(description = "审核时间")
        private LocalDateTime auditTime;

        @Schema(description = "审核管理员ID")
        private Long auditAdminId;

        @Schema(description = "审核备注")
        private String auditRemark;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "审核统计响应")
    public static class AuditStatsResponse {
        @Schema(description = "待审核数量")
        private Long pendingCount;

        @Schema(description = "今日审核通过数量")
        private Long todayApprovedCount;

        @Schema(description = "今日审核拒绝数量")
        private Long todayRejectedCount;

        @Schema(description = "总审核数量")
        private Long totalAuditedCount;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "审核历史查询请求")
    public static class AuditHistoryQueryRequest {
        @Builder.Default
        @Schema(description = "页码", example = "1")
        private Integer page = 1;

        @Builder.Default
        @Schema(description = "每页数量", example = "20")
        private Integer size = 20;

        @Schema(description = "审核状态筛选", example = "approved")
        private String auditStatus;

        @Schema(description = "审核管理员ID筛选")
        private Long auditAdminId;

        @Schema(description = "开始时间", example = "2025-10-01 00:00:00")
        private LocalDateTime startTime;

        @Schema(description = "结束时间", example = "2025-10-31 23:59:59")
        private LocalDateTime endTime;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "审核历史记录")
    public static class AuditHistoryRecord {
        @Schema(description = "审核记录ID")
        private Long id;

        @Schema(description = "作品编号")
        private String workNo;

        @Schema(description = "作品标题")
        private String workTitle;

        @Schema(description = "审核状态")
        private String auditStatus;

        @Schema(description = "审核管理员ID")
        private Long auditAdminId;

        @Schema(description = "审核管理员名称")
        private String auditAdminName;

        @Schema(description = "审核备注")
        private String auditRemark;

        @Schema(description = "审核时间")
        private LocalDateTime auditTime;
    }

    /**
     * 作品详细审核信息（含历史记录）
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "作品详细审核信息")
    public static class WorkAuditDetailResponse {
        
        @Schema(description = "作品基本信息")
        private PendingWorkDetailResponse workInfo;

        @Schema(description = "当前审核状态")
        private String auditStatus;

        @Schema(description = "当前审核备注")
        private String auditRemark;

        @Schema(description = "当前审核时间")
        private LocalDateTime auditTime;

        @Schema(description = "当前审核管理员")
        private String auditAdminName;

        @Schema(description = "历史审核记录")
        private java.util.List<AuditHistoryRecord> auditHistory;

        @Schema(description = "作者历史作品通过率")
        private Double authorApprovalRate;

        @Schema(description = "作者累计发布作品数")
        private Integer authorTotalWorks;
    }

    /**
     * 审核员工作量统计
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "审核员工作量统计")
    public static class AdminWorkloadStatsResponse {
        
        @Schema(description = "审核员ID")
        private Long adminId;

        @Schema(description = "审核员名称")
        private String adminName;

        @Schema(description = "统计时间段-开始")
        private String startTime;

        @Schema(description = "统计时间段-结束")
        private String endTime;

        @Schema(description = "总审核数量")
        private Long totalAudited;

        @Schema(description = "通过数量")
        private Long approvedCount;

        @Schema(description = "拒绝数量")
        private Long rejectedCount;

        @Schema(description = "通过率")
        private Double approvalRate;

        @Schema(description = "平均审核时长（分钟）")
        private Double avgAuditTimeMinutes;

        @Schema(description = "最忙碌日期")
        private String busiestDate;

        @Schema(description = "最忙碌日期审核数")
        private Long busiestDateCount;
    }

    /**
     * 撤销审核请求
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "撤销审核请求")
    public static class RevokeAuditRequest {
        
        @NotBlank(message = "作品编号不能为空")
        @Schema(description = "作品编号", example = "WORK-20251026183750127-8554")
        private String workNo;

        @NotBlank(message = "撤销原因不能为空")
        @Schema(description = "撤销原因", example = "误审，需要重新审核")
        private String reason;
    }
}

