import {
  IsString,
  IsUUID,
  IsOptional,
  IsDateString,
  MaxLength,
  IsArray,
  ValidateNested,
  ArrayMinSize,
  Matches,
} from 'class-validator';
import {
  DOCUMENT_URL_PATTERN,
  DOCUMENT_URL_MESSAGE,
} from '../../../common/validation/document-url';
import { Type, Transform } from 'class-transformer';

export class CreateTicketItemDto {
  @IsString()
  @MaxLength(100)
  ticket_type: string;

  @IsString()
  @MaxLength(50)
  age_group: string;

  @IsString()
  @MaxLength(255)
  ticket_ref_no: string;

  @IsOptional()
  @IsString()
  @MaxLength(500)
  @Matches(DOCUMENT_URL_PATTERN, { message: DOCUMENT_URL_MESSAGE })
  @Transform(({ value }) => (value === '' ? undefined : value))
  document_url?: string;

  @IsOptional()
  @IsString()
  @MaxLength(1000)
  notes?: string;
}

export class CreateActivityTicketBatchDto {
  @IsUUID()
  activity_id: string;

  @IsOptional()
  @IsUUID()
  supplier_id?: string;

  @IsOptional()
  @IsDateString()
  valid_from?: string;

  @IsOptional()
  @IsDateString()
  valid_to?: string;

  @IsOptional()
  @IsString()
  @MaxLength(50)
  time_slot?: string;

  @IsOptional()
  @IsString()
  notes?: string;

  /**
   * Optional booking reference or booking ID.
   * When set, Movement Dashboard will only show this batch for that booking.
   */
  /** Comma-separated booking UUIDs. Multiple bookings can share a batch. */
  @IsOptional()
  @IsString()
  booking_reference_no?: string;

  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => CreateTicketItemDto)
  items: CreateTicketItemDto[];
}
