/**
 * Database Monitoring Stub
 *
 * This module previously provided PostgreSQL-specific monitoring (slow queries,
 * connection pool stats, table bloat, index usage, locks) via direct SQL.
 * Since the project has migrated to Convex, these metrics are no longer
 * available through raw SQL. The class is retained as a stub so the
 * /api/health/database/monitoring route compiles without changes.
 *
 * All methods return sensible empty/default values.
 */

export interface SlowQuery {
  query: string;
  calls: number;
  mean_time: number;
  total_time: number;
  rows: number;
}

export interface ConnectionPoolStats {
  active_connections: number;
  idle_connections: number;
  waiting_connections: number;
  max_connections: number;
  utilization_percent: number;
}

export interface TableBloat {
  table_name: string;
  dead_tuples: number;
  live_tuples: number;
  bloat_percent: number;
  last_autovacuum: string | null;
}

export interface IndexStats {
  index_name: string;
  table_name: string;
  index_size: string;
  index_scans: number;
}

export interface LockInfo {
  pid: number;
  mode: string;
  relation: string;
  granted: boolean;
  query: string;
  duration: string;
}

export interface MonitoringReport {
  timestamp: string;
  slow_queries: SlowQuery[];
  connection_pool: ConnectionPoolStats;
  table_bloat: TableBloat[];
  unused_indexes: IndexStats[];
  active_locks: LockInfo[];
}

/**
 * DatabaseMonitor stub.
 * Returns empty/default data for all monitoring methods since the project
 * no longer uses PostgreSQL directly.
 */
export class DatabaseMonitor {
  async getSlowQueries(_limit?: number): Promise<SlowQuery[]> {
    return [];
  }

  async getConnectionPoolStats(): Promise<ConnectionPoolStats> {
    return {
      active_connections: 0,
      idle_connections: 0,
      waiting_connections: 0,
      max_connections: 0,
      utilization_percent: 0,
    };
  }

  async getTableBloat(): Promise<TableBloat[]> {
    return [];
  }

  async getUnusedIndexes(): Promise<IndexStats[]> {
    return [];
  }

  async getActiveLocks(): Promise<LockInfo[]> {
    return [];
  }

  async generateReport(): Promise<MonitoringReport> {
    return {
      timestamp: new Date().toISOString(),
      slow_queries: [],
      connection_pool: await this.getConnectionPoolStats(),
      table_bloat: [],
      unused_indexes: [],
      active_locks: [],
    };
  }

  async enableSlowQueryTracking(): Promise<void> {
    // No-op: PostgreSQL pg_stat_statements not available with Convex
  }

  async resetSlowQueryStats(): Promise<void> {
    // No-op: PostgreSQL pg_stat_statements not available with Convex
  }
}
