// Shared partner-domain types. The partner UI is now fully on real data (the
// old data/customers.ts fixture module has been deleted); these view-model
// types live here and are imported by pages and composables. CustomerOrg in
// particular remains the shape the customer screens bind to, populated by
// mapping real /api/partner/tenants rows onto it.

// Currencies the platform prices in. Subscriptions are always reported
// per-currency (never FX-summed), so this propagates through MRR + billing.
export type Currency = 'DKK' | 'EUR' | 'USD'

// Display status for a customer org in the partner UI. Broader than the
// backend Tenant.status enum (active/pending/suspended/deleted) — it also
// carries billing-derived states (past_due, trial, attention) that the
// partner screens distinguish. Mapping from real Tenant data happens in the
// page/composable layer.
export type CustomerStatus = 'healthy' | 'attention' | 'past_due' | 'trial' | 'suspended'

// The shape the partner customer screens render. Originally a pure fixture
// type; retained as the view-model the table/cards bind to while real data
// is mapped onto it.
export interface CustomerOrg {
  id: string
  name: string
  domain: string
  plan: 'starter' | 'business' | 'enterprise'
  planLabel: 'Starter' | 'Business' | 'Enterprise'
  seats: { used: number; total: number }
  health: number
  status: CustomerStatus
  mrrDkk: number
  brandColor: string
  industry: string
  createdOn: string
  since: string
}

// Canonical shape of a tenant as returned by /api/partner/tenants
// (platform-api /me/partner/tenants). Previously duplicated — and subtly
// divergent — between the dashboard and customers pages. This superset is the
// single source of truth; `usePartnerTenants` returns it.
export interface PartnerTenantDoc {
  _id: string
  slug: string
  name: string
  status: 'active' | 'pending' | 'suspended' | 'deleted'
  plan?: 'mvp' | 'pro' | 'enterprise'
  seats?: number
  // Active User docs whose tenantIds include this tenant — server-side
  // aggregation, so the "used / total" seats column needs no second fetch.
  userCount?: number
  // Active users created in the last 30 days (for the dashboard delta).
  newUserCount30d?: number
  domains?: string[]
  createdAt?: string
  // Partner-editable customer metadata.
  industry?: string
  brandColor?: string
  // Computed server-side (never stored): 0–100 portfolio-health score + band.
  healthScore?: number
  healthBand?: 'healthy' | 'watch' | 'at-risk'
  provisioningStatus?: {
    authentik?: 'pending' | 'ok' | 'error' | 'skipped'
    stalwart?: 'pending' | 'ok' | 'error' | 'skipped'
    ocis?: 'pending' | 'ok' | 'error' | 'skipped'
  }
}

// One subscription's normalized monthly amount, in minor units (e.g. 4900 =
// 49.00). `custom: true` marks Enterprise / pre-catalog subs with no priced
// amount — those render as "custom" rather than a misleading 0.
export interface MrrBreakdownRow {
  tenantId: string
  tenantName?: string
  currency: Currency
  monthlyMinor: number
  custom: boolean
}

// Response of /api/partner/mrr. Totals are grouped by currency so a partner
// with mixed-currency customers sees a per-currency total, not an FX-fudged
// single number.
export interface MrrResponse {
  totals: Array<{ currency: Currency; monthlyMinor: number }>
  breakdown: MrrBreakdownRow[]
}
