export interface TenantResponse {
  id: string;
  name: string;
  slug: string;
  tier: string;
  status: string;
  serverEndpoint: string | null;
  provisionError: string | null;
  createdAt: string;
  updatedAt: string;
}

export interface LicenseResponse {
  id: string;
  tenantId: string;
  tier: string;
  features: Record<string, boolean>;
  limits: Record<string, number>;
  issuedAt: string;
  expiresAt: string;
  token: string;
}

export interface MeResponse {
  userId: string;
  tenants: Array<{
    id: string;
    name: string;
    slug: string;
    logtoOrgId: string;
  }>;
}

// Vendor API types
export interface VendorTenantSummary {
  id: string;
  name: string;
  slug: string;
  tier: string;
  status: string;
  serverState: string;
  licenseExpiry: string | null;
  provisionError: string | null;
  agentCount: number;
  environmentCount: number;
  agentLimit: number;
}

export interface VendorTenantDetail {
  tenant: TenantResponse;
  serverState: string;
  serverHealthy: boolean;
  serverStatus: string;
  license: LicenseResponse | null;
}

export interface CreateTenantRequest {
  name: string;
  slug: string;
  tier?: string;
  adminUsername?: string;
  adminPassword?: string;
}

// Tenant portal API types
export interface DashboardData {
  name: string;
  slug: string;
  tier: string;
  status: string;
  serverHealthy: boolean;
  serverStatus: string;
  serverEndpoint: string | null;
  licenseTier: string | null;
  licenseDaysRemaining: number;
  limits: Record<string, number>;
  features: Record<string, boolean>;
  agentCount: number;
  environmentCount: number;
}

export interface TenantLicenseData {
  id: string;
  tier: string;
  features: Record<string, boolean>;
  limits: Record<string, number>;
  issuedAt: string;
  expiresAt: string;
  token: string;
  daysRemaining: number;
}

export interface TenantSettings {
  name: string;
  slug: string;
  tier: string;
  status: string;
  serverEndpoint: string | null;
  createdAt: string;
}

// SSO connector types
export interface SsoConnector {
  id: string;
  providerName: string;
  connectorName: string;
  config: Record<string, unknown>;
  domains: string[];
  branding?: { displayName?: string; logo?: string };
  syncProfile: boolean;
  createdAt: string;
}

export interface CreateSsoConnectorRequest {
  providerName: string;
  connectorName: string;
  config: Record<string, unknown>;
  domains: string[];
}

export interface SsoTestResult {
  status: string;
  providerName: string;
  connectorName: string;
}

// Audit log types
export interface AuditLogEntry {
  id: string;
  actorEmail: string | null;
  tenantId: string | null;
  action: string;
  resource: string | null;
  environment: string | null;
  result: string;
  sourceIp: string | null;
  createdAt: string;
}

export interface AuditLogPage {
  content: AuditLogEntry[];
  page: number;
  size: number;
  totalElements: number;
  totalPages: number;
}

export interface AuditLogFilters {
  action?: string;
  result?: string;
  search?: string;
  from?: string;
  to?: string;
  tenantId?: string;
  page?: number;
  size?: number;
}

// Tenant metrics (from server /api/v1/admin/metrics/summary)
export interface AgentMetrics {
  live: number;
  stale: number;
  dead: number;
  shutdown: number;
}

export interface IngestionMetrics {
  bufferDepth: number;
  dropsPerMinute: number;
}

export interface ServerMetrics {
  cpuUsage: number;
  heapUsedBytes: number;
  heapMaxBytes: number;
  uptimeSeconds: number;
  threadCount: number;
}

export interface HttpMetrics {
  requestsPerMinute: number;
  errorRate: number;
}

export interface MetricsSummary {
  collectedAt: string;
  agents: AgentMetrics;
  ingestion: IngestionMetrics;
  server: ServerMetrics;
  http: HttpMetrics;
  authFailuresPerMinute: number;
}

export interface TenantMetricsEntry {
  tenantId: string;
  tenantName: string;
  slug: string;
  tier: string;
  status: string;
  serverState: string;
  metrics: MetricsSummary | null;
}
