import type { Room } from "@/types/hotel"
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"

export function getBookedHotelRoom(
  rooms: Room[],
  roomTypeCode: BookingConfirmation["booking"]["roomTypeCode"]
) {
  if (!rooms.length || !roomTypeCode) {
    return null
  }
  const room = rooms.find((r) => {
    return r.roomTypes.find((roomType) => roomType.code === roomTypeCode)
  })
  if (!room) {
    return null
  }
  const bedType = room.roomTypes.find(
    (roomType) => roomType.code === roomTypeCode
  )
  if (!bedType) {
    return null
  }
  return {
    ...room,
    bedType,
  }
}
