import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsBoolean,
  IsEnum,
  IsInt,
  IsOptional,
  IsString,
  Max,
  Min,
} from 'class-validator';
import { ToBoolean } from '../../common/transforms/to-boolean.transform.js';
import { DictionaryType } from '../../generated/prisma/enums.js';

/**
 * 系统字典项创建 DTO。
 */
export class CreateDictionaryItemDto {
  @ApiProperty({
    description: '字典类型',
    enum: DictionaryType,
    example: DictionaryType.PRIMARY_DISEASE,
  })
  @IsEnum(DictionaryType, { message: 'type 枚举值不合法' })
  type!: DictionaryType;

  @ApiProperty({
    description: '字典项名称',
    example: '先天性脑积水',
  })
  @IsString({ message: 'label 必须是字符串' })
  label!: string;

  @ApiPropertyOptional({
    description: '排序值，越小越靠前，默认 0',
    example: 10,
    default: 0,
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt({ message: 'sortOrder 必须是整数' })
  @Min(-9999, { message: 'sortOrder 不能小于 -9999' })
  @Max(9999, { message: 'sortOrder 不能大于 9999' })
  sortOrder?: number;

  @ApiPropertyOptional({
    description: '是否启用，默认 true',
    example: true,
    default: true,
  })
  @IsOptional()
  @ToBoolean()
  @IsBoolean({ message: 'enabled 必须是布尔值' })
  enabled?: boolean;
}
