// Shape returned by /api/tenants — matches Tenant schema on platform-api.
// Kept in a separate file so multiple pages can import without copying.

export type TenantStatus = 'pending' | 'active' | 'suspended' | 'deleted'
export type TenantPlan = 'mvp' | 'pro' | 'enterprise'
export type IntegrationState = 'pending' | 'ok' | 'error' | 'skipped'

export interface Tenant {
  _id: string
  slug: string
  name: string
  status: TenantStatus
  plan: TenantPlan
  domains: string[]
  partnerId?: string
  authentikGroupId?: string
  ocisSpaceId?: string
  stalwartDomain?: string
  billingInfo: {
    companyName?: string
    vatId?: string
    country?: string
    contactEmail?: string
  }
  provisioningStatus: {
    authentik: IntegrationState
    stalwart: IntegrationState
    ocis: IntegrationState
  }
  provisioningErrors: {
    authentik?: string
    stalwart?: string
    ocis?: string
  }
  createdAt: string
  updatedAt: string
}

export interface TenantUser {
  _id: string
  authentikSubjectId: string
  email: string
  name: string
  // Global/legacy role + fallback. Prefer `tenantRole` for display in a tenant
  // context — `role` can differ from the user's actual role in this tenant.
  role: 'owner' | 'admin' | 'member'
  // Role resolved for THIS tenant (per-tenant override, else global `role`).
  // Set by GET /tenants/:slug/users.
  tenantRole: 'owner' | 'admin' | 'member'
  active: boolean
  platformAdmin: boolean
  tenantIds: string[]
  lastLoginAt?: string
  createdAt: string
}
