// Read-only proxy to the public slots endpoint, used by the admin reschedule
// picker so an operator rebooks against the same live free/busy a customer sees.
// The upstream is unauthenticated, so no token is forwarded.
export default defineEventHandler(async (event) => {
  const tenantSlug = getRouterParam(event, 'tenantSlug')!
  const hostSlug = getRouterParam(event, 'hostSlug')!
  const eventTypeSlug = getRouterParam(event, 'eventTypeSlug')!
  const query = getQuery(event)
  const base = process.env.PLATFORM_API_INTERNAL_URL ?? 'http://platform-api:3001'
  const path = `/api/v1/public/${encodeURIComponent(tenantSlug)}/${encodeURIComponent(hostSlug)}/${encodeURIComponent(eventTypeSlug)}/slots`
  try {
    return await $fetch(base + path, { query })
  } catch (err: any) {
    const status = err?.response?.status ?? 502
    const raw = err?.data?.message ?? err?.response?._data?.message ?? 'Upstream error'
    throw createError({ statusCode: status, statusMessage: Array.isArray(raw) ? raw.join(', ') : String(raw) })
  }
})
