import type { DefaultFilterOptions } from "@/types/components/hotelReservation/selectRate/roomFilter"
import type {
  Rate,
  Room as RoomBooking,
  SelectRateBooking,
} from "@/types/components/hotelReservation/selectRate/selectRate"
import type { CurrencyEnum } from "@/types/enums/currency"
import type { Room } from "@/types/hotel"
import type { Package, PackageEnum } from "@/types/requests/packages"
import type {
  Product,
  RoomConfiguration,
  RoomsAvailability,
} from "@/types/trpc/routers/hotel/roomAvailability"
import type { BookingCodeFilterEnum } from "../enums/bookingCodeFilter"

export interface AvailabilityError {
  details: string
  error: string
}

interface Actions {
  appendRegularRates: (
    roomConfigurations: RoomConfiguration[] | undefined
  ) => void
  closeSection: () => void
  modifyRate: () => void
  removeSelectedPackage: (code: PackageEnum) => void
  removeSelectedPackages: () => void
  selectFilter: (filter: BookingCodeFilterEnum) => void
  selectPackages: (codes: PackageEnum[]) => void
  selectRate: (rate: SelectedRate, isUserLoggedIn: boolean) => void
  updateRooms: (rooms: RoomConfiguration[] | undefined) => void
}

export interface SelectedRate {
  features: RoomConfiguration["features"]
  product: Product
  roomType: RoomConfiguration["roomType"]
  roomTypeCode: RoomConfiguration["roomTypeCode"]
}

export interface SelectedRoom {
  actions: Actions
  bookingRoom: RoomBooking
  isFetchingAdditionalRate: boolean
  isFetchingPackages: boolean
  rooms: RoomConfiguration[]
  selectedFilter: BookingCodeFilterEnum | undefined
  selectedPackages: Package[]
  selectedRate: SelectedRate | null
}

export interface RatesState {
  activeRoom: number
  booking: SelectRateBooking
  hotelType: string | undefined
  isRedemptionBooking: boolean
  packageOptions: DefaultFilterOptions[]
  rateSummary: Array<Rate | null>
  rooms: SelectedRoom[]
  roomCategories: Room[]
  roomConfigurations: RoomConfiguration[][]
  roomsPackages: Package[][]
  roomsAvailability: (RoomsAvailability | AvailabilityError)[] | undefined
  vat: number
  defaultCurrency: CurrencyEnum
}

export interface InitialState
  extends Pick<
    RatesState,
    "booking" | "hotelType" | "roomCategories" | "roomsAvailability" | "vat"
  > {
  initialActiveRoom?: number
  pathname: string
  labels: {
    accessibilityRoom: string
    allergyRoom: string
    petRoom: string
  }
}
