import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsNumber,
  IsIn,
  IsArray,
  ArrayNotEmpty,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';

export class BatchParticipantDto {
  @IsNotEmpty()
  @IsString()
  participant_name: string;

  @IsOptional()
  @IsString()
  participant_company?: string;
}

/**
 * One training session → many participants.
 * Course details are entered once; a certificate + QR is
 * generated for every participant in the list.
 */
export class BatchCreateTrainingCertificatesDto {
  @IsNotEmpty()
  @IsString()
  course_title: string;

  @IsOptional()
  @IsNumber()
  standard_id?: number;

  @IsNotEmpty()
  @IsString()
  training_location: string;

  @IsNotEmpty()
  @Type(() => Date)
  training_date: Date;

  // Optional second date — for multi-day trainings (e.g. "6 and 7 July 2026")
  @IsOptional()
  @Type(() => Date)
  training_date_end?: Date;

  // Leave empty = certificates never expire
  @IsOptional()
  @Type(() => Date)
  valid_until?: Date;

  @IsOptional()
  @IsString()
  @IsIn(['local', 'international'])
  verification_domain?: string;

  @IsOptional()
  @IsNumber()
  created_by?: number;

  @IsArray()
  @ArrayNotEmpty()
  @ValidateNested({ each: true })
  @Type(() => BatchParticipantDto)
  participants: BatchParticipantDto[];
}