package com.dora.dto;

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

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

/**
 * 课程视频详情DTO
 */
@Data
@Schema(description = "课程视频详情")
public class CourseVideoDetailDto {

    @Schema(description = "课程基本信息")
    private CourseInfo course;

    @Schema(description = "章节列表（包含视频信息）")
    private List<ChapterInfo> chapters;

    @Schema(description = "用户权限信息")
    private UserPermission userPermission;

    @Data
    @Schema(description = "课程基本信息")
    public static class CourseInfo {
        @Schema(description = "课程ID")
        private Long id;

        @Schema(description = "课程标题")
        private String title;

        @Schema(description = "课程描述")
        private String description;

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

        @Schema(description = "详情图集（JSON格式存储多张图片URL）")
        private String detailGallery;

        @Schema(description = "价格")
        private BigDecimal price;

        @Schema(description = "总观看次数")
        private Integer viewCount;

        @Schema(description = "访问级别（0-游客/1-普通/2-VIP/3-SVIP）")
        private Integer level;

        @Schema(description = "分类")
        private String category;

        @Schema(description = "是否免费")
        private Boolean isFree;

        @Schema(description = "级别名称")
        private String levelName;

        @Schema(description = "创建时间")
        private LocalDateTime createTime;

        @Schema(description = "更新时间")
        private LocalDateTime updateTime;

        @Schema(description = "创建者信息")
        private CreatorInfo creator;
    }

    @Data
    @Schema(description = "章节信息")
    public static class ChapterInfo {
        @Schema(description = "章节ID")
        private Long id;

        @Schema(description = "章节标题")
        private String title;

        @Schema(description = "章节描述")
        private String description;

        @Schema(description = "排序号")
        private Integer orderNum;

        @Schema(description = "视频列表")
        private List<VideoInfo> videos;
    }

    @Data
    @Schema(description = "视频信息")
    public static class VideoInfo {
        @Schema(description = "视频条目ID")
        private Long id;

        @Schema(description = "所属章节ID")
        private Long chapterId;

        @Schema(description = "视频标题")
        private String title;

        @Schema(description = "阿里云点播视频ID")
        private String vodVideoId;

        @Schema(description = "视频封面URL")
        private String coverUrl;

        @Schema(description = "时长(秒)")
        private Integer durationSec;

        @Schema(description = "格式化时长")
        private String durationFormatted;

        @Schema(description = "排序号")
        private Integer orderNum;

        @Schema(description = "是否可播放（基于用户权限）")
        private Boolean canPlay;

        @Schema(description = "锁定原因（如果不能播放）")
        private String lockReason;
    }

    @Data
    @Schema(description = "创建者信息")
    public static class CreatorInfo {
        @Schema(description = "创建者ID")
        private String id;

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

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

    @Data
    @Schema(description = "用户权限信息")
    public static class UserPermission {
        @Schema(description = "用户角色（0-游客/1-普通/2-VIP/3-SVIP）")
        private Integer userRole;

        @Schema(description = "用户角色名称")
        private String userRoleName;

        @Schema(description = "课程要求的最低级别")
        private Integer requiredLevel;

        @Schema(description = "课程要求的级别名称")
        private String requiredLevelName;

        @Schema(description = "是否有课程访问权限")
        private Boolean hasAccess;

        @Schema(description = "无权限访问的原因")
        private String accessDeniedReason;

        @Schema(description = "会员到期时间")
        private LocalDateTime membershipExpiresAt;
    }
}