/**
 * GetConnectionStatusUseCase
 * 
 * Retrieves current connection status and metrics.
 * This Use Case orchestrates the retrieval of connection status information.
 */

import { HealthCheckQuery, ConnectionHealth, ConnectionStatus } from '../ports/HealthCheckQuery';

export interface GetConnectionStatusUseCasePorts {
  healthCheckAdapter: HealthCheckQuery;
}

export interface ConnectionStatusResult {
  status: ConnectionStatus;
  reliability: number;
  totalRequests: number;
  successfulRequests: number;
  failedRequests: number;
  consecutiveFailures: number;
  averageResponseTime: number;
  lastCheck: Date | null;
  lastSuccess: Date | null;
  lastFailure: Date | null;
}

export class GetConnectionStatusUseCase {
  constructor(private readonly ports: GetConnectionStatusUseCasePorts) {}

  /**
   * Execute to get current connection status
   */
  async execute(): Promise<ConnectionStatusResult> {
    const { healthCheckAdapter } = this.ports;

    const health = healthCheckAdapter.getHealth();
    const reliability = healthCheckAdapter.getReliability();

    return {
      status: health.status,
      reliability,
      totalRequests: health.totalRequests,
      successfulRequests: health.successfulRequests,
      failedRequests: health.failedRequests,
      consecutiveFailures: health.consecutiveFailures,
      averageResponseTime: health.averageResponseTime,
      lastCheck: health.lastCheck,
      lastSuccess: health.lastSuccess,
      lastFailure: health.lastFailure,
    };
  }
}
