package com.dora.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.util.List;

/**
 * 内容提交审核 DTO（支持视频、工作流、课程集合）
 */
public class ContentReviewDto {

    @Data
    @Schema(description = "内容提交审核请求")
    public static class SubmitRequest {
        @NotBlank(message = "内容类型不能为空")
        @Schema(description = "内容类型（video/workflow/course）", example = "video", allowableValues = {"video", "workflow", "course"})
        private String contentType;

        @NotBlank(message = "内容ID不能为空")
        @Schema(description = "内容ID", example = "30e9e19b744371f0bf9887c6371c0102")
        private String contentId;

        @Schema(description = "视频名称（contentType=video 时有效）", example = "我的视频标题")
        private String videoTitle;

        @Schema(description = "视频描述（contentType=video 时有效）", example = "视频详细介绍")
        private String videoDescription;

        @Schema(description = "视频封面URL（contentType=video 时有效）", example = "https://example.com/cover.jpg")
        private String videoCoverUrl;

        @Schema(description = "视频分类（contentType=video 时有效）", example = "教育")
        private String videoCategory;

        @Schema(description = "视频时长（秒，contentType=video 时有效）", example = "120")
        private Integer videoDuration;

        @Schema(description = "工作流名称（contentType=workflow 时有效）", example = "我的工作流")
        private String workflowName;

        @Schema(description = "工作流描述（contentType=workflow 时有效）", example = "工作流详细介绍")
        private String workflowDescription;

        @Schema(description = "视频合集ID（可选）", example = "123")
        private Long collectionId;

        @Schema(description = "前端指定的课程外部ID（可选）。用于零返回创建课程与多视频归类。例如：course-abc-001")
        private String courseExternalId;

        @Schema(description = "课程名称（contentType=course 时有效）", example = "我的课程")
        private String courseTitle;

        @Schema(description = "课程描述（contentType=course 时有效）", example = "课程详细介绍")
        private String courseDescription;

        @Schema(description = "课程分类（contentType=course 时有效）", example = "教育")
        private String courseCategory;

        @Schema(description = "课程封面URL（contentType=course 时有效）", example = "https://example.com/course-cover.jpg")
        private String courseCoverUrl;

        @Schema(description = "课程是否免费（contentType=course 时有效，0=收费，1=免费）", example = "0")
        private Integer courseIsFree;

        @Schema(description = "课程访问所需最低用户级别（contentType=course 时有效，0=游客，1=普通，2=VIP，3=SVIP）", example = "2")
        private Integer courseLevel;
    }

    @Data
    @Schema(description = "课程集合提交审核请求")
    public static class CourseCollectionSubmitRequest {
        @NotBlank(message = "课程集合ID不能为空")
        @Schema(description = "前端指定的课程集合ID，用于标识整个课程集合", example = "course-collection-001")
        private String courseCollectionId;

        @NotBlank(message = "课程标题不能为空")
        @Schema(description = "课程标题", example = "我的系列课程")
        private String courseTitle;

        @Schema(description = "课程描述", example = "课程详细介绍")
        private String courseDescription;

        @Schema(description = "课程分类", example = "教育")
        private String courseCategory;

        @Schema(description = "课程封面URL", example = "https://example.com/course-cover.jpg")
        private String courseCoverUrl;

        @NotNull(message = "课程是否免费不能为空")
        @Schema(description = "课程是否免费：0收费 / 1免费", example = "0")
        private Integer courseIsFree;

        @NotNull(message = "课程访问级别不能为空")
        @Schema(description = "课程访问所需最低用户级别：0游客/1普通/2VIP/3SVIP", example = "2")
        private Integer courseLevel;

        @Schema(description = "课程详情图集(JSON数组字符串)", example = "[\"https://oss.../detail1.jpg\",\"https://oss.../detail2.jpg\"]")
        private String detailGallery;

        @NotNull(message = "课程章节列表不能为空")
        @Size(min = 1, message = "至少需要包含一个章节")
        @Schema(description = "课程章节列表")
        private List<CourseItem> chapters;
    }

    @Data
    @Schema(description = "课程章节项")
    public static class CourseItem {
        @NotBlank(message = "章节标题不能为空")
        @Schema(description = "章节标题", example = "第一章：基础入门")
        private String chapterTitle;

        @Schema(description = "章节描述", example = "本章节介绍基础知识")
        private String chapterDescription;

        @NotBlank(message = "视频ID不能为空")
        @Schema(description = "关联的视频ID", example = "30e9e19b744371f0bf9887c6371c0102")
        private String videoId;

        @Schema(description = "视频标题", example = "视频标题")
        private String videoTitle;

        @Schema(description = "视频描述", example = "视频描述")
        private String videoDescription;

        @Schema(description = "视频封面URL", example = "https://example.com/cover.jpg")
        private String videoCoverUrl;

        @Schema(description = "视频分类", example = "教育")
        private String videoCategory;

        @Schema(description = "视频时长（秒）", example = "120")
        private Integer videoDuration;

        @Schema(description = "章节排序（可选，不传则自动递增）", example = "1")
        private Integer orderNum;
    }

    @Data
    @Schema(description = "内容提交审核响应")
    public static class SubmitResponse {
        @Schema(description = "内容类型")
        private String contentType;

        @Schema(description = "内容ID")
        private String contentId;

        @Schema(description = "审核状态(0待审核/1通过/2拒绝)")
        private Integer auditStatus;

        @Schema(description = "提交结果说明")
        private String message;

        @Schema(description = "自动创建的课程ID（当提交视频并自动归类为课程时返回）")
        private Long courseId;
    }

    @Data
    @Schema(description = "课程集合提交审核响应")
    public static class CourseCollectionSubmitResponse {
        @Schema(description = "课程集合ID")
        private String courseCollectionId;

        @Schema(description = "创建的课程ID")
        private Long courseId;

        @Schema(description = "审核状态(0待审核/1通过/2拒绝)")
        private Integer auditStatus;

        @Schema(description = "提交结果说明")
        private String message;

        @Schema(description = "成功创建的章节数量")
        private Integer chapterCount;
    }

    @Data
    @Schema(description = "课程集合提交审核请求（v2，支持每章多视频）")
    public static class CourseCollectionV2SubmitRequest {
        @NotBlank(message = "课程集合ID不能为空")
        @Schema(description = "前端指定的课程集合ID，用于标识整个课程集合", example = "course-collection-001")
        private String courseCollectionId;

        @NotBlank(message = "课程标题不能为空")
        @Schema(description = "课程标题", example = "我的系列课程")
        private String courseTitle;

        @Schema(description = "课程描述", example = "课程详细介绍")
        private String courseDescription;

        @Schema(description = "课程分类", example = "教育")
        private String courseCategory;

        @Schema(description = "课程封面URL", example = "https://example.com/course-cover.jpg")
        private String courseCoverUrl;

        @NotNull(message = "课程是否免费不能为空")
        @Schema(description = "课程是否免费：0收费 / 1免费", example = "0")
        private Integer courseIsFree;

        @NotNull(message = "课程访问级别不能为空")
        @Schema(description = "课程访问所需最低用户级别：0游客/1普通/2VIP/3SVIP", example = "2")
        private Integer courseLevel;

        @Schema(description = "课程详情图集(JSON数组字符串)", example = "[\"https://oss.../detail1.jpg\",\"https://oss.../detail2.jpg\"]")
        private String detailGallery;

        @NotNull(message = "课程章节列表不能为空")
        @Size(min = 1, message = "至少需要包含一个章节")
        @Schema(description = "课程章节列表")
        private java.util.List<ChapterV2> chapters;
    }

    @Data
    @Schema(description = "课程章节项（v2）")
    public static class ChapterV2 {
        @NotBlank(message = "章节标题不能为空")
        @Schema(description = "章节标题", example = "第一章：基础入门")
        private String chapterTitle;

        @Schema(description = "章节描述", example = "本章节介绍基础知识")
        private String chapterDescription;

        @Schema(description = "章节排序（可选，不传则自动递增）", example = "1")
        private Integer orderNum;

        @NotNull(message = "章节下的视频列表不能为空")
        @Size(min = 1, message = "每个章节至少包含一个视频")
        @Schema(description = "章节内视频列表")
        private java.util.List<CourseVideoItem> videos;
    }

    @Data
    @Schema(description = "课程章节内的视频项（v2）")
    public static class CourseVideoItem {
        @NotBlank(message = "视频ID不能为空")
        @Schema(description = "关联的视频ID（VOD字符串ID）", example = "30e9e19b744371f0bf9887c6371c0102")
        private String videoId;

        @Schema(description = "视频标题", example = "视频标题")
        private String videoTitle;

        @Schema(description = "视频描述", example = "视频描述")
        private String videoDescription;

        @Schema(description = "视频封面URL", example = "https://example.com/cover.jpg")
        private String videoCoverUrl;

        @Schema(description = "视频分类", example = "教育")
        private String videoCategory;

        @Schema(description = "视频时长（秒）", example = "120")
        private Integer videoDuration;

        @Schema(description = "视频在章节内的排序（可选）", example = "1")
        private Integer orderNum;
    }
}


