/**
 * Monitoring types for system health and metrics
 */

export interface CacheStats {
  provider: string;
  connected: boolean;
  uptime?: number;
  memoryUsage?: {
    used: number;
    peak: number;
    total?: number;
  };
  stats?: {
    hits: number;
    misses: number;
    keys: number;
    evictedKeys?: number;
    expiredKeys?: number;
  };
  info?: Record<string, any>;
}

export interface QueueStats {
  name: string;
  service: string;
  queue: string;
  connected: boolean;
  jobs: {
    waiting: number;
    active: number;
    completed: number;
    failed: number;
    delayed: number;
    paused: number;
    prioritized?: number;
    'waiting-children'?: number;
  };
  workers?: {
    count: number;
    concurrency: number;
  };
  throughput?: {
    processed: number;
    failed: number;
    avgProcessingTime?: number;
  };
}

export interface DatabaseStats {
  type: 'postgres' | 'mongodb' | 'questdb';
  name: string;
  connected: boolean;
  latency?: number;
  pool?: {
    size: number;
    active: number;
    idle: number;
    waiting?: number;
    max: number;
  };
  stats?: Record<string, any>;
}

export interface SystemHealth {
  status: 'healthy' | 'degraded' | 'unhealthy';
  timestamp: string;
  uptime: number;
  memory: {
    used: number;
    total: number;
    percentage: number;
  };
  cpu?: {
    usage: number;
    loadAverage?: number[];
  };
  services: {
    cache: CacheStats;
    queues: QueueStats[];
    databases: DatabaseStats[];
  };
  errors?: string[];
}

export interface MetricSnapshot {
  timestamp: string;
  value: number;
  unit?: string;
}

export interface ServiceMetrics {
  requestsPerSecond: MetricSnapshot;
  averageResponseTime: MetricSnapshot;
  errorRate: MetricSnapshot;
  activeConnections: MetricSnapshot;
}

export interface ServiceStatus {
  name: string;
  version: string;
  status: 'running' | 'stopped' | 'error';
  port?: number;
  uptime: number;
  lastCheck: string;
  healthy: boolean;
  error?: string;
}

export interface ProxyStats {
  enabled: boolean;
  totalProxies: number;
  workingProxies: number;
  failedProxies: number;
  lastUpdate?: string;
  lastFetchTime?: string;
}

export interface SystemOverview {
  services: ServiceStatus[];
  health: SystemHealth;
  proxies?: ProxyStats;
  environment: {
    nodeVersion: string;
    platform: string;
    architecture: string;
    hostname: string;
  };
}
