export type DomainType = "subdomain" | "custom" | "platform" | "app" | "admin" | "api";

export type TenantStatus = "pending" | "active" | "suspended" | "archived";

/**
 * Trusted server-side tenant context.
 * NEVER construct this from client-supplied tenant_id.
 * Always resolve via hostname / verified domain.
 */
export type TenantContext = {
  tenantId: string;
  tenantSlug: string;
  studioName: string;
  status: TenantStatus;
  hostname: string;
  domainId: string | null;
  domainType: DomainType;
  isPrimaryDomain: boolean;
};

export type HostKind =
  | { kind: "platform" }
  | { kind: "app" }
  | { kind: "admin" }
  | { kind: "api" }
  | { kind: "tenant_subdomain"; slug: string }
  | { kind: "custom_domain"; domain: string }
  | { kind: "unknown" };

export class TenantResolutionError extends Error {
  readonly code: "NOT_FOUND" | "SUSPENDED" | "INACTIVE" | "INVALID_HOST";

  constructor(
    code: TenantResolutionError["code"],
    message: string,
  ) {
    super(message);
    this.name = "TenantResolutionError";
    this.code = code;
  }
}
