import { getCountries } from "@/server/routers/hotels/utils"
import { getServiceToken } from "@/server/tokenManager"

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

export const warmupCountry =
  (lang: Lang): WarmupFunction =>
  async (): Promise<WarmupResult> => {
    try {
      const serviceToken = await getServiceToken()

      await getCountries({
        lang: lang,
        serviceToken: serviceToken.access_token,
        warmup: true,
      })
    } catch (error) {
      return {
        status: "error",
        error: error as Error,
      }
    }

    return {
      status: "completed",
    }
  }
