import { z } from "zod"

import { ChildBedTypeEnum } from "@/constants/booking"

const roomsSchema = z.array(
  z.object({
    adults: z.number().int().nonnegative(),
    childrenAges: z
      .array(
        z.object({
          age: z.number().int().nonnegative(),
          bedType: z.nativeEnum(ChildBedTypeEnum),
        })
      )
      .default([]),
    rateCode: z.string(),
    roomTypeCode: z.coerce.string(),
    guest: z.object({
      firstName: z.string(),
      lastName: z.string(),
      email: z.string().email(),
      phoneNumber: z.string(),
      countryCode: z.string(),
      membershipNumber: z.string().optional(),
    }),
    smsConfirmationRequested: z.boolean(),
    packages: z.object({
      breakfast: z.boolean(),
      allergyFriendly: z.boolean(),
      petFriendly: z.boolean(),
      accessibility: z.boolean(),
    }),
    roomPrice: z.number().or(z.string().transform((val) => Number(val))),
  })
)

const paymentSchema = z.object({
  paymentMethod: z.string(),
  card: z
    .object({
      alias: z.string(),
      expiryDate: z.string(),
      cardType: z.string(),
    })
    .optional(),
  cardHolder: z
    .object({
      email: z.string().email(),
      name: z.string(),
      phoneCountryCode: z.string(),
      phoneSubscriber: z.string(),
    })
    .optional(),
  success: z.string(),
  error: z.string(),
  cancel: z.string(),
})

// Mutation
export const createBookingInput = z.object({
  hotelId: z.string(),
  checkInDate: z.string(),
  checkOutDate: z.string(),
  rooms: roomsSchema,
  payment: paymentSchema,
})

// Query
const confirmationNumberInput = z.object({
  confirmationNumber: z.string(),
})

export const bookingConfirmationInput = confirmationNumberInput

export const getBookingStatusInput = confirmationNumberInput
