import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

const RAJAONGKIR_API_BASE = "https://rajaongkir.komerce.id/api/v1"

export async function GET(req: MedusaRequest, res: MedusaResponse) {
  const apiKey = process.env.RAJAONGKIR_API_KEY

  if (!apiKey) {
    return res.status(500).json({
      message: "RajaOngkir API key not configured",
    })
  }

  const response = await fetch(`${RAJAONGKIR_API_BASE}/destination/province`, {
    headers: { key: apiKey },
  })

  const result = await response.json()
  res.json(result)
}
