import { z } from "zod"

import {
  corporateChequeProduct,
  priceProduct,
  productSchema,
  redemptionProduct,
  voucherProduct,
} from "./product"

import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"

export const roomConfigurationSchema = z.object({
  breakfastIncludedInAllRatesMember: z.boolean().default(false),
  breakfastIncludedInAllRates: z.boolean().default(false),
  features: z
    .array(
      z.object({
        inventory: z.number(),
        code: z.enum([
          RoomPackageCodeEnum.PET_ROOM,
          RoomPackageCodeEnum.ALLERGY_ROOM,
          RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
        ]),
      })
    )
    .default([]),
  products: z.array(productSchema).default([]),
  roomsLeft: z.number(),
  roomType: z.string(),
  roomTypeCode: z.string(),
  status: z
    .nativeEnum(AvailabilityEnum)
    .nullish()
    .default(AvailabilityEnum.NotAvailable),

  // Red
  campaign: z
    .array(priceProduct)
    .optional()
    .transform((val) => (val ? val.filter(Boolean) : [])),
  // Blue
  code: z
    .array(z.union([corporateChequeProduct, priceProduct, voucherProduct]))
    .optional()
    .transform((val) => (val ? val.filter(Boolean) : [])),
  // Beige
  regular: z
    .array(priceProduct)
    .optional()
    .transform((val) => (val ? val.filter(Boolean) : [])),
  // Burgundy
  redemptions: z
    .array(redemptionProduct)
    .optional()
    .transform((val) => (val ? val.filter(Boolean) : [])),
})
