import {
  IsArray,
  IsNotEmpty,
  IsOptional,
  IsString,
  IsBoolean,
  IsNumber,
  IsUUID,
  MaxLength,
  Min,
  ValidateIf,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { CreateActivityTicketSlotDto } from './create-activity-ticket-slot.dto';

export class CreateActivityTicketDto {
  @ValidateIf((o) => !!o.id)
  @IsUUID()
  id?: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(255)
  name: string;

  @IsString()
  @IsOptional()
  @MaxLength(100)
  internal_ref?: string;

  // time_slot removed — slot windows live in activity_ticket_slots.

  @IsNumber()
  @IsOptional()
  @Min(0)
  duration_mins?: number;

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

  @IsBoolean()
  @IsOptional()
  is_active?: boolean;

  /** Child slot rows — one entry per availability window or departure.
   *  Empty array OR omitted = no slots; service syncs by (ticket, label):
   *  upsert incoming, soft-delete existing rows not in the new list. */
  @IsArray()
  @IsOptional()
  @ValidateNested({ each: true })
  @Type(() => CreateActivityTicketSlotDto)
  slots?: CreateActivityTicketSlotDto[];
}
