import { IsString, IsNotEmpty, IsOptional, IsInt, IsArray, IsEnum, Min } from 'class-validator';

export enum LibraryType {
  PICTURE_BOOK = 'PICTURE_BOOK',
  MATERIAL = 'MATERIAL',
  TEMPLATE = 'TEMPLATE',
}

export enum FileType {
  IMAGE = 'IMAGE',
  PDF = 'PDF',
  VIDEO = 'VIDEO',
  AUDIO = 'AUDIO',
  PPT = 'PPT',
  OTHER = 'OTHER',
}

export class CreateLibraryDto {
  @IsString()
  @IsNotEmpty({ message: '资源库名称不能为空' })
  name: string;

  @IsEnum(LibraryType)
  libraryType: LibraryType;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsString()
  coverImage?: string;
}

export class UpdateLibraryDto {
  @IsOptional()
  @IsString()
  @IsNotEmpty({ message: '资源库名称不能为空' })
  name?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsString()
  coverImage?: string;

  @IsOptional()
  @IsInt()
  @Min(0)
  sortOrder?: number;
}

export class CreateResourceItemDto {
  @IsInt()
  @IsNotEmpty({ message: '资源库ID不能为空' })
  libraryId: number;

  @IsString()
  @IsNotEmpty({ message: '资源名称不能为空' })
  title: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsEnum(FileType)
  fileType: FileType;

  @IsString()
  @IsNotEmpty({ message: '文件路径不能为空' })
  filePath: string;

  @IsOptional()
  @IsInt()
  fileSize?: number;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  tags?: string[];
}

export class UpdateResourceItemDto {
  @IsOptional()
  @IsString()
  @IsNotEmpty({ message: '资源名称不能为空' })
  title?: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  tags?: string[];

  @IsOptional()
  @IsInt()
  @Min(0)
  sortOrder?: number;
}

export class QueryLibraryDto {
  @IsOptional()
  @IsInt()
  page?: number;

  @IsOptional()
  @IsInt()
  pageSize?: number;

  @IsOptional()
  @IsString()
  libraryType?: string;

  @IsOptional()
  @IsString()
  keyword?: string;
}

export class QueryResourceItemDto {
  @IsOptional()
  @IsInt()
  page?: number;

  @IsOptional()
  @IsInt()
  pageSize?: number;

  @IsOptional()
  @IsInt()
  libraryId?: number;

  @IsOptional()
  @IsString()
  fileType?: string;

  @IsOptional()
  @IsString()
  keyword?: string;
}
