import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '@environments/environment';
import { Observable } from 'rxjs';

export interface OperatorStats {
  operatorId: string;
  totalTransactions: number;
  successRate: number;
  totalRevenue: number;
  averageLatency: number;
  errorCount: number;
  uptime: number;
  dailyStats: DailyStat[];
}

export interface DailyStat {
  date: string;
  transactions: number;
  successRate: number;
  revenue: number;
}

@Injectable({ providedIn: 'root' })
export class OperatorStatsService {
  private http = inject(HttpClient);
  private apiUrl = `${environment.localServiceTestApiUrl}/operators`;

  getOperatorStats(operatorId: string): Observable<OperatorStats> {
    return this.http.get<OperatorStats>(
      `${this.apiUrl}/${operatorId}/stats`
    );
  }

  getOperatorsComparison(): Observable<any[]> {
    return this.http.get<any[]>(`${this.apiUrl}/comparison`);
  }

  getPerformanceMetrics(operatorId: string, period: string): Observable<any> {
    return this.http.get(
      `${this.apiUrl}/${operatorId}/metrics?period=${period}`
    );
  }
}