// Shared fetch of the signed-in partner's customer tenants from
// /api/partner/tenants (platform-api /me/partner/tenants). Several pages need
// this list — dashboard, customers, and (later) billing — and they all key the
// fetch as 'partner-tenants', so Nuxt dedupes to a single round-trip and shared
// payload. Centralizing it here removes the divergent inline PartnerTenantDoc
// copies that drifted between pages.
//
// Synchronous (non-async) so `useFetch` is invoked directly in the caller's
// setup context — safe to call after another `await` in setup, unlike an async
// wrapper. Call WITHOUT await:
//   const { tenants, refresh } = usePartnerTenants()

import type { PartnerTenantDoc } from '~/types/partner'

export function usePartnerTenants() {
  const { data: tenants, refresh, error, pending } = useFetch<PartnerTenantDoc[]>(
    '/api/partner/tenants',
    { key: 'partner-tenants', default: () => [] },
  )
  return { tenants, refresh, error, pending }
}
