import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { EmptyStringToUndefined } from '../../common/transforms/empty-string-to-undefined.transform.js';
import { UploadAssetType } from '../../generated/prisma/enums.js';
import {
  IsEnum,
  IsInt,
  IsOptional,
  IsString,
  Max,
  Min,
} from 'class-validator';

/**
 * 上传资产查询 DTO：用于图库/视频库分页筛选。
 */
export class UploadAssetQueryDto {
  @ApiPropertyOptional({
    description: '关键词（按原始文件名模糊匹配）',
    example: 'ct',
  })
  @IsOptional()
  @IsString({ message: 'keyword 必须是字符串' })
  keyword?: string;

  @ApiPropertyOptional({
    description: '资产类型',
    enum: UploadAssetType,
    example: UploadAssetType.IMAGE,
  })
  @IsOptional()
  @IsEnum(UploadAssetType, { message: 'type 枚举值不合法' })
  type?: UploadAssetType;

  @ApiPropertyOptional({ description: '医院 ID（SYSTEM_ADMIN 可选）', example: 1 })
  @IsOptional()
  @EmptyStringToUndefined()
  @Type(() => Number)
  @IsInt({ message: 'hospitalId 必须是整数' })
  @Min(1, { message: 'hospitalId 必须大于 0' })
  hospitalId?: number;

  @ApiPropertyOptional({ description: '页码', example: 1, default: 1 })
  @IsOptional()
  @EmptyStringToUndefined()
  @Type(() => Number)
  @IsInt({ message: 'page 必须是整数' })
  @Min(1, { message: 'page 最小为 1' })
  page?: number = 1;

  @ApiPropertyOptional({
    description: '每页数量',
    example: 20,
    default: 20,
  })
  @IsOptional()
  @EmptyStringToUndefined()
  @Type(() => Number)
  @IsInt({ message: 'pageSize 必须是整数' })
  @Min(1, { message: 'pageSize 最小为 1' })
  @Max(100, { message: 'pageSize 最大为 100' })
  pageSize?: number = 20;
}
