import apiClient from './client'
import type { FlowPilotDashboard, KnowledgeGapReport, CoverageResponse, FlowQualityResponse, EnhancedPsaMetrics } from '@/types/flowpilot-analytics'

export const flowpilotAnalyticsApi = {
  async getDashboard(period: string = '30d'): Promise<FlowPilotDashboard> {
    const response = await apiClient.get<FlowPilotDashboard>('/analytics/flowpilot', {
      params: { period },
    })
    return response.data
  },

  async getKnowledgeGaps(period: string = '30d'): Promise<KnowledgeGapReport> {
    const response = await apiClient.get<KnowledgeGapReport>('/analytics/flowpilot/knowledge-gaps', {
      params: { period },
    })
    return response.data
  },

  async getCoverage(period: string = '30d'): Promise<CoverageResponse> {
    const response = await apiClient.get<CoverageResponse>('/analytics/flowpilot/coverage', {
      params: { period },
    })
    return response.data
  },

  async getFlowQuality(period: string = '30d', sort: string = 'quality'): Promise<FlowQualityResponse> {
    const response = await apiClient.get<FlowQualityResponse>('/analytics/flowpilot/flow-quality', {
      params: { period, sort },
    })
    return response.data
  },

  async getPsaMetrics(period: string = '30d'): Promise<EnhancedPsaMetrics> {
    const response = await apiClient.get<EnhancedPsaMetrics>('/analytics/flowpilot/psa-metrics', {
      params: { period },
    })
    return response.data
  },
}

export default flowpilotAnalyticsApi
