import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  ArrayMaxSize,
  IsArray,
  IsBoolean,
  IsOptional,
  IsString,
  MaxLength,
} from 'class-validator';
import { ToBoolean } from '../../common/transforms/to-boolean.transform.js';

/**
 * 植入物目录创建 DTO。
 */
export class CreateImplantCatalogDto {
  @ApiProperty({
    description: '型号编码',
    example: 'CODMAN-HAKIM-120',
  })
  @IsString({ message: 'modelCode 必须是字符串' })
  modelCode!: string;

  @ApiProperty({
    description: '厂家',
    example: 'Codman',
  })
  @IsString({ message: 'manufacturer 必须是字符串' })
  manufacturer!: string;

  @ApiProperty({
    description: '名称',
    example: 'Hakim 可调压阀',
  })
  @IsString({ message: 'name 必须是字符串' })
  name!: string;

  @ApiPropertyOptional({
    description: '是否为阀门，关闭时表示管子或附件',
    example: true,
  })
  @IsOptional()
  @ToBoolean()
  @IsBoolean({ message: 'isValve 必须是布尔值' })
  isValve?: boolean;

  @ApiPropertyOptional({
    description: '可调压器械的挡位列表，按字符串挡位标签录入',
    type: [String],
    example: ['0.5', '1', '1.5'],
  })
  @IsOptional()
  @IsArray({ message: 'pressureLevels 必须是数组' })
  @ArrayMaxSize(30, { message: 'pressureLevels 最多 30 项' })
  @IsString({ each: true, message: 'pressureLevels 必须为字符串数组' })
  pressureLevels?: string[];

  @ApiPropertyOptional({
    description: '植入物备注',
    example: '适用于儿童脑积水病例',
  })
  @IsOptional()
  @IsString({ message: 'notes 必须是字符串' })
  @MaxLength(200, { message: 'notes 最长 200 个字符' })
  notes?: string;
}
