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 jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 广场作品DTO
 * 
 * @author 1818AI
 * @since 2025-10-26
 */
public class PlazaWorkDto {

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

    /**
     * 发布作品请求
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "发布作品请求")
    public static class PublishWorkRequest {
        
        @NotBlank(message = "任务编号不能为空")
        @Schema(description = "任务编号", example = "TASK-20251026183750127-8554")
        private String taskNo;
        
        @Schema(description = "作品标题", example = "战场气氛短视频")
        private String title;
        
        @Schema(description = "作品描述", example = "根据参考图生成的恢弘战场场景")
        private String description;
        
        @Schema(description = "标签列表", example = "[\"视频\", \"战争\", \"特效\"]")
        private List<String> tags;
        
        @NotNull(message = "是否公开不能为空")
        @Schema(description = "是否公开", example = "true")
        private Boolean isPublic;
    }

    /**
     * 作品查询请求
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "作品查询请求")
    public static class WorkQueryRequest {
        
        @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;
        
        @Builder.Default
        @Schema(description = "排序方式：latest-最新，hot-最热", example = "latest")
        private String sortBy = "latest";
        
        @Schema(description = "状态筛选", example = "published")
        private String status;
    }

    /**
     * 作品详情响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "作品详情响应")
    public static class WorkDetailResponse {
        
        @Schema(description = "作品编号")
        private String workNo;
        
        @Schema(description = "任务编号")
        private String taskNo;
        
        @Schema(description = "任务类型")
        private String taskType;
        
        @Schema(description = "模型名称")
        private String modelName;
        
        @Schema(description = "生成提示词")
        private String prompt;
        
        @Schema(description = "作品结果URL")
        private String resultUrl;
        
        @Schema(description = "参考图URL")
        private String imageUrl;
        
        @Schema(description = "宽高比")
        private String aspectRatio;
        
        @Schema(description = "作品标题")
        private String title;
        
        @Schema(description = "作品描述")
        private String description;
        
        @Schema(description = "标签列表")
        private List<String> tags;
        
        @Schema(description = "浏览次数")
        private Integer viewCount;
        
        @Schema(description = "点赞数")
        private Integer likeCount;
        
        @Schema(description = "分享数")
        private Integer shareCount;
        
        @Schema(description = "当前用户是否已点赞")
        private Boolean isLiked;
        
        @Schema(description = "作者信息")
        private WorkAuthorDto author;
        
        @Schema(description = "创建时间")
        private LocalDateTime createTime;
        
        @Schema(description = "更新时间")
        private LocalDateTime updateTime;
        
        @Schema(description = "任务状态（仅未发布任务）", example = "completed", allowableValues = {"queued", "processing", "completed", "failed"})
        private String taskStatus;
        
        @Schema(description = "任务进度（仅未发布任务）", example = "100")
        private Integer taskProgress;
        
        @Schema(description = "错误信息（仅未发布任务失败时）")
        private String errorMessage;
    }

    /**
     * 作品列表项响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "作品列表项响应")
    public static class WorkListItemResponse {
        
        @Schema(description = "作品编号")
        private String workNo;
        
        @Schema(description = "任务类型")
        private String taskType;
        
        @Schema(description = "模型名称")
        private String modelName;
        
        @Schema(description = "生成提示词（截取）")
        private String prompt;
        
        @Schema(description = "作品结果URL")
        private String resultUrl;
        
        @Schema(description = "作品标题")
        private String title;
        
        @Schema(description = "标签列表")
        private List<String> tags;
        
        @Schema(description = "浏览次数")
        private Integer viewCount;
        
        @Schema(description = "点赞数")
        private Integer likeCount;
        
        @Schema(description = "当前用户是否已点赞")
        private Boolean isLiked;
        
        @Schema(description = "作者信息")
        private WorkAuthorDto author;
        
        @Schema(description = "创建时间")
        private LocalDateTime createTime;
    }

    /**
     * 作品列表分页响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "作品列表分页响应")
    public static class WorkListResponse {
        
        @Schema(description = "总数")
        private Long total;
        
        @Schema(description = "作品列表")
        private List<WorkListItemResponse> list;
    }

    /**
     * 作者信息DTO
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "作者信息")
    public static class WorkAuthorDto {
        
        @Schema(description = "用户ID")
        private Long userId;
        
        @Schema(description = "昵称")
        private String nickname;
        
        @Schema(description = "头像URL")
        private String avatarUrl;
    }

    /**
     * 点赞响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "点赞响应")
    public static class LikeResponse {
        
        @Schema(description = "是否已点赞")
        private Boolean isLiked;
        
        @Schema(description = "点赞数")
        private Integer likeCount;
    }

    /**
     * 广场统计响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "广场统计响应")
    public static class PlazaStatsResponse {
        
        @Schema(description = "总作品数")
        private Long totalWorks;
        
        @Schema(description = "总浏览数")
        private Long totalViews;
        
        @Schema(description = "总点赞数")
        private Long totalLikes;
        
        @Schema(description = "按类型统计")
        private java.util.Map<String, Long> worksByType;
    }

    /**
     * 用户点赞列表响应
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "用户点赞列表响应")
    public static class UserLikedWorksResponse {
        
        @Schema(description = "总数")
        private Long total;
        
        @Schema(description = "点赞的作品列表")
        private List<LikedWorkItem> list;
    }

    /**
     * 点赞的作品项
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "点赞的作品项")
    public static class LikedWorkItem {
        
        @Schema(description = "点赞记录ID")
        private Long likeId;
        
        @Schema(description = "作品编号")
        private String workNo;
        
        @Schema(description = "任务类型")
        private String taskType;
        
        @Schema(description = "模型名称")
        private String modelName;
        
        @Schema(description = "生成提示词（截取）")
        private String prompt;
        
        @Schema(description = "作品结果URL")
        private String resultUrl;
        
        @Schema(description = "作品标题")
        private String title;
        
        @Schema(description = "标签列表")
        private List<String> tags;
        
        @Schema(description = "浏览次数")
        private Integer viewCount;
        
        @Schema(description = "点赞数")
        private Integer likeCount;
        
        @Schema(description = "作者信息")
        private WorkAuthorDto author;
        
        @Schema(description = "点赞时间")
        private LocalDateTime likedTime;
        
        @Schema(description = "作品创建时间")
        private LocalDateTime createTime;
    }
}

