import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  ArrayMaxSize,
  ArrayMinSize,
  IsArray,
  IsInt,
  IsOptional,
  IsString,
  Min,
} from 'class-validator';

/**
 * 手术下设备 DTO：描述一次手术中植入的设备实例。
 */
export class CreateSurgeryDeviceDto {
  @ApiProperty({
    description: '植入物型号编号，选中后自动回填厂家与名称',
    example: 1,
  })
  @Type(() => Number)
  @IsInt({ message: 'implantCatalogId 必须是整数' })
  @Min(1, { message: 'implantCatalogId 必须大于 0' })
  implantCatalogId!: number;

  @ApiProperty({
    description: '分流方式',
    example: 'VPS',
  })
  @IsString({ message: 'shuntMode 必须是字符串' })
  shuntMode!: string;

  @ApiProperty({
    description: '近端穿刺区域，最多 2 个',
    type: [String],
    example: ['额角', '枕角'],
  })
  @IsArray({ message: 'proximalPunctureAreas 必须是数组' })
  @ArrayMinSize(1, { message: 'proximalPunctureAreas 至少选择 1 项' })
  @ArrayMaxSize(2, { message: 'proximalPunctureAreas 最多选择 2 项' })
  @IsString({ each: true, message: 'proximalPunctureAreas 必须为字符串数组' })
  proximalPunctureAreas!: string[];

  @ApiPropertyOptional({
    description: '阀门植入部位，阀门型植入物最多 2 个',
    type: [String],
    example: ['耳后', '胸前'],
  })
  @IsOptional()
  @IsArray({ message: 'valvePlacementSites 必须是数组' })
  @ArrayMaxSize(2, { message: 'valvePlacementSites 最多选择 2 项' })
  @IsString({ each: true, message: 'valvePlacementSites 必须为字符串数组' })
  valvePlacementSites?: string[];

  @ApiProperty({
    description: '远端分流方向',
    example: '腹腔',
  })
  @IsString({ message: 'distalShuntDirection 必须是字符串' })
  distalShuntDirection!: string;

  @ApiPropertyOptional({
    description: '初始压力挡位，可为空',
    example: '1.5',
  })
  @IsOptional()
  @IsString({ message: 'initialPressure 必须是字符串' })
  initialPressure?: string;

  @ApiPropertyOptional({
    description: '植入物备注',
    example: '术中顺利，通畅良好',
  })
  @IsOptional()
  @IsString({ message: 'implantNotes 必须是字符串' })
  implantNotes?: string;

  @ApiPropertyOptional({
    description: '植入物标签图片地址',
    example: 'https://cdn.example.com/patients/device-label-001.jpg',
  })
  @IsOptional()
  @IsString({ message: 'labelImageUrl 必须是字符串' })
  labelImageUrl?: string;
}
