import { apiRequest } from '../lib/api'
import type { DashboardLocale } from '@meshkee/dashboard-core'
import type { BusinessPrimaryColorId } from '../utils/businessPrimaryColors'

export interface ResolvedTenant {
  id: string
  name: string
  nameFa: string | null
  slug: string
  domain: string
  primaryColor: BusinessPrimaryColorId
  defaultLocale?: DashboardLocale
  logoUrl?: string | null
  faviconUrl?: string | null
}

export async function resolveTenantByDomain(host: string, signal?: AbortSignal) {
  const encodedHost = encodeURIComponent(host)
  return apiRequest<ResolvedTenant>(`/tenants/${encodedHost}`, { signal })
}
