import type { CalculatePricesPerNightProps } from "@/types/components/hotelReservation/selectRate/roomCard"

export function calculatePricesPerNight({
  publicLocalPrice,
  memberLocalPrice,
  publicRequestedPrice,
  memberRequestedPrice,
  petRoomLocalPrice,
  petRoomRequestedPrice,
  nights,
}: CalculatePricesPerNightProps) {
  const totalPublicLocalPricePerNight = publicLocalPrice
    ? petRoomLocalPrice
      ? Math.floor(
          Number(publicLocalPrice.pricePerNight) +
            Number(petRoomLocalPrice.price) / nights
        )
      : Math.floor(Number(publicLocalPrice.pricePerNight))
    : undefined

  const totalMemberLocalPricePerNight = memberLocalPrice
    ? petRoomLocalPrice
      ? Math.floor(
          Number(memberLocalPrice.pricePerNight) +
            Number(petRoomLocalPrice.price) / nights
        )
      : Math.floor(Number(memberLocalPrice.pricePerNight))
    : undefined

  const totalPublicRequestedPricePerNight = publicRequestedPrice
    ? petRoomRequestedPrice
      ? Math.floor(
          Number(publicRequestedPrice.pricePerNight) +
            Number(petRoomRequestedPrice.price) / nights
        )
      : Math.floor(Number(publicRequestedPrice.pricePerNight))
    : undefined

  const totalMemberRequestedPricePerNight = memberRequestedPrice
    ? petRoomRequestedPrice
      ? Math.floor(
          Number(memberRequestedPrice.pricePerNight) +
            Number(petRoomRequestedPrice.price) / nights
        )
      : Math.floor(Number(memberRequestedPrice.pricePerNight))
    : undefined

  return {
    totalPublicLocalPricePerNight,
    totalMemberLocalPricePerNight,
    totalPublicRequestedPricePerNight,
    totalMemberRequestedPricePerNight,
  }
}
