import { env } from "@/env/server"
import { serverClient } from "@/lib/trpc/server"

import type { Lang } from "@/constants/languages"
import type { WarmupFunction, WarmupResult } from "."

export const warmupHotelData =
  (lang: Lang): WarmupFunction =>
  async (): Promise<WarmupResult> => {
    if (!env.ENABLE_WARMUP_HOTEL) {
      return {
        status: "skipped",
      }
    }

    try {
      const caller = await serverClient()
      await caller.hotel.hotels.getDestinationsMapData({
        lang,
        warmup: true,
      })
    } catch (error) {
      return {
        status: "error",
        error: error as Error,
      }
    }

    return {
      status: "completed",
    }
  }
