package com.dora.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;

/**
 * 搜索相关DTO
 */
public class SearchDto {
    
    // 私有构造函数，防止实例化
    private SearchDto() {
    }

    /**
     * 搜索请求DTO
     */
    @Data
    @Schema(description = "搜索请求")
    public static class SearchRequest {
        
        @Schema(description = "搜索关键词", example = "AI图像处理")
        private String keyword;
        
        @Schema(description = "内容类型", example = "all", allowableValues = {"all", "course", "workflow"})
        private String type = "all";
        
        @Schema(description = "分类过滤", example = "人工智能")
        private String category;
        
        @Schema(description = "是否仅显示免费内容", example = "false")
        private Boolean freeOnly;
        
        @Schema(description = "排序方式", example = "relevance", allowableValues = {"relevance", "createTime", "updateTime", "viewCount", "likeCount"})
        private String sortBy = "relevance";
        
        @Schema(description = "排序方向", example = "desc", allowableValues = {"asc", "desc"})
        private String sortOrder = "desc";
        
        @Schema(description = "页码", example = "1", minimum = "1")
        private Integer page = 1;
        
        @Schema(description = "每页数量", example = "20", minimum = "1", maximum = "100")
        private Integer size = 20;
    }

    /**
     * 搜索响应DTO
     */
    @Data
    @Schema(description = "搜索响应")
    public static class SearchResponse {
        
        @Schema(description = "搜索结果总数", example = "156")
        private Long total;
        
        @Schema(description = "当前页码", example = "1")
        private Integer page;
        
        @Schema(description = "每页数量", example = "20")
        private Integer size;
        
        @Schema(description = "总页数", example = "8")
        private Integer totalPages;
        
        @Schema(description = "搜索关键词", example = "AI图像处理")
        private String keyword;
        
        @Schema(description = "搜索结果列表")
        private List<SearchResultItem> items;
    }

    /**
     * 搜索结果项DTO
     */
    @Data
    @Schema(description = "搜索结果项")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class SearchResultItem {
        
        @Schema(description = "内容ID", example = "1")
        private Long id;
        
        @Schema(description = "内容类型", example = "course", allowableValues = {"course", "workflow"})
        private String type;
        
        @Schema(description = "标题/名称", example = "AI图像处理入门课程")
        private String title;
        
        @Schema(description = "描述", example = "学习AI图像处理的基础知识和实践技巧")
        private String description;
        
        @Schema(description = "封面图URL", example = "https://example.com/cover1.jpg")
        private String coverUrl;
        
        @Schema(description = "价格", example = "29.99")
        private String price;
        
        @Schema(description = "分类", example = "人工智能")
        private String category;
        
        @Schema(description = "是否免费", example = "false")
        private Boolean isFree;
        
        @Schema(description = "点赞数", example = "1250")
        private Integer likeCount;
        
        // 课程特有字段
        @Schema(description = "访问级别（仅课程）", example = "1")
        private Integer level;
        
        @Schema(description = "课程时长（仅课程）", example = "15:30")
        private String duration;
        
        @Schema(description = "观看次数（仅课程）", example = "12500")
        private Integer viewCount;
        
        @Schema(description = "评论数（仅课程）", example = "856")
        private Integer commentCount;
        
        @Schema(description = "VIP类型（仅课程）", example = "normal")
        private String vipType;
        
        // 工作流特有字段
        @Schema(description = "评分（仅工作流）", example = "5")
        private Integer rating;
        
        @Schema(description = "查看完整数据所需最低角色（0-游客/1-普通/2-VIP/3-SVIP）", example = "2")
        private Integer fullAccessRole;
        
        @Schema(description = "查看完整数据所需角色名称", example = "VIP用户")
        private String fullAccessRoleName;
        
        @Schema(description = "复制所需最低角色（0-游客/1-普通/2-VIP/3-SVIP）", example = "2")
        private Integer copyAccessRole;
        
        @Schema(description = "复制所需角色名称", example = "VIP用户")
        private String copyAccessRoleName;
        
        @Schema(description = "创建者信息")
        private CreatorInfo creator;
        
        @Schema(description = "创建时间", example = "2024-01-15T10:30:00")
        private String createTime;
        
        @Schema(description = "更新时间", example = "2024-01-15T10:30:00")
        private String updateTime;
    }

    /**
     * 创建者信息DTO
     */
    @Data
    @Schema(description = "创建者信息")
    public static class CreatorInfo {
        
        @Schema(description = "创建者ID", example = "17543607206742139")
        private String id;
        
        @Schema(description = "创建者用户名", example = "张三")
        private String username;
        
        @Schema(description = "创建者头像URL", example = "https://example.com/avatar1.jpg")
        private String avatarUrl;
    }

    /**
     * 搜索统计DTO
     */
    @Data
    @Schema(description = "搜索统计信息")
    public static class SearchStats {
        
        @Schema(description = "课程总数", example = "89")
        private Long courseCount;
        
        @Schema(description = "工作流总数", example = "67")
        private Long workflowCount;
        
        @Schema(description = "总数", example = "156")
        private Long totalCount;
        
        @Schema(description = "分类统计")
        private List<CategoryStats> categoryStats;
    }

    /**
     * 分类统计DTO
     */
    @Data
    @Schema(description = "分类统计")
    public static class CategoryStats {
        
        @Schema(description = "分类名称", example = "人工智能")
        private String categoryName;
        
        @Schema(description = "该分类下的内容数量", example = "45")
        private Long count;
    }
}
