import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  Allow,
  IsArray,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  ValidateNested,
} from 'class-validator';

export class SeatTransferUserDto {
  @ApiProperty({ description: 'ID of the target user to transfer the seat to', example: 9271 })
  @IsNotEmpty() @IsNumber()
  userId: number;
}

export class SeatTransferAnswerDto {
  @ApiProperty({ description: 'Program question ID', example: 7468 })
  @IsNumber()
  questionId: number;

  @ApiProperty({
    description: 'Answer value — string, number, boolean, or array depending on question type',
    example: 'Madhuri Karedla',
  })
  @Allow()
  answer: any;
}

export class SeatTransferDto {
  @ApiProperty({ type: SeatTransferUserDto, description: 'Target user to transfer the seat to' })
  @ValidateNested() @Type(() => SeatTransferUserDto)
  user: SeatTransferUserDto;

  @ApiPropertyOptional({
    type: [SeatTransferAnswerDto],
    description: 'Registration field answers to override on the transferred registration. Only registration-table fields (fullName, dob, email, mobile, etc.) are applied — payment and invoice fields are ignored.',
  })
  @IsOptional() @IsArray() @ValidateNested({ each: true }) @Type(() => SeatTransferAnswerDto)
  answers?: SeatTransferAnswerDto[];

  @ApiPropertyOptional({ description: 'Reason for the seat transfer', example: 'Participant unable to attend, transferring to colleague' })
  @IsOptional() @IsString()
  transferReason?: string;

  @ApiPropertyOptional({ description: 'Internal admin notes about this transfer' })
  @IsOptional() @IsString()
  adminNotes?: string;
}
