import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsInt,
  IsOptional,
  IsString,
  Matches,
  Min,
  ValidateNested,
} from 'class-validator';
import { CreatePatientSurgeryDto } from './create-patient-surgery.dto.js';

/**
 * 患者创建 DTO：B 端新增患者使用。
 */
export class CreatePatientDto {
  @ApiProperty({ description: '患者姓名', example: '张三' })
  @IsString({ message: 'name 必须是字符串' })
  name!: string;

  @ApiPropertyOptional({ description: '住院号', example: 'ZYH-20260319001' })
  @IsOptional()
  @IsString({ message: 'inpatientNo 必须是字符串' })
  inpatientNo?: string;

  @ApiPropertyOptional({ description: '项目名称', example: '脑积水随访项目' })
  @IsOptional()
  @IsString({ message: 'projectName 必须是字符串' })
  projectName?: string;

  @ApiProperty({ description: '手机号', example: '13800002001' })
  @IsString({ message: 'phone 必须是字符串' })
  @Matches(/^1\d{10}$/, { message: 'phone 必须是合法手机号' })
  phone!: string;

  @ApiProperty({
    description: '身份证号原文',
    example: '110101199001010011',
  })
  @IsString({ message: 'idCard 必须是字符串' })
  idCard!: string;

  @ApiProperty({ description: '归属人员编号（医生/主任/组长）', example: 10001 })
  @Type(() => Number)
  @IsInt({ message: 'doctorId 必须是整数' })
  @Min(1, { message: 'doctorId 必须大于 0' })
  doctorId!: number;

  @ApiPropertyOptional({
    description: '首台手术信息，可在创建患者时一并录入',
    type: CreatePatientSurgeryDto,
  })
  @IsOptional()
  @ValidateNested()
  @Type(() => CreatePatientSurgeryDto)
  initialSurgery?: CreatePatientSurgeryDto;
}
