import {
  IsArray,
  IsBoolean,
  IsIn,
  IsNumber,
  IsOptional,
  IsString,
  MaxLength,
  Min,
} from 'class-validator';

/**
 * Enum of allowed extra kinds — mirrored by the CHECK constraint on
 * booking_hotel_extras / query_quote_hotel_extras. Keep the string
 * literals in sync with:
 *   - HotelExtraKind on the frontend (itinerary-helpers.ts)
 *   - ck_*_hotel_extras_kind CHECK constraints
 */
export const HOTEL_EXTRA_KINDS = ['AWEB', 'CNB', 'CUSTOM'] as const;

export type HotelExtraKind = (typeof HOTEL_EXTRA_KINDS)[number];

/**
 * One "room booking" period line — shared shape for both the quote
 * and the booking side (identical columns on both child tables).
 */
export class HotelPeriodDto {
  @IsNumber() @IsOptional() sort_order?: number;

  /** 0-based night indexes into the parent stay window. */
  @IsArray()
  @IsNumber({}, { each: true })
  nights: number[];

  @IsString() @IsOptional() @MaxLength(100) room_type?: string;
  @IsString() @IsOptional() @MaxLength(100) meal_plan?: string;

  @IsNumber() @Min(1) num_rooms: number;
  @IsNumber() @Min(1) pax_per_room: number;
  @IsNumber() @Min(0) rate_per_night: number;
}

/**
 * One extra / add-on line — shared shape for both sides.
 */
export class HotelExtraDto {
  @IsNumber() @IsOptional() sort_order?: number;

  @IsIn(HOTEL_EXTRA_KINDS as unknown as string[])
  kind: HotelExtraKind;

  @IsString() @IsOptional() @MaxLength(200) description?: string | null;

  @IsNumber() @Min(0) quantity: number;
  @IsNumber() @Min(0) rate: number;

  @IsArray()
  @IsNumber({}, { each: true })
  nights: number[];

  @IsBoolean() @IsOptional() scale_by_rooms?: boolean;
}
