/**
 * Serviço de Analytics e KPIs
 */

import { apiClient } from "../api/client";
import type { KPISummary } from "./types";

class AnalyticsService {
  /**
   * Busca resumo de KPIs
   */
  async getSummary(): Promise<KPISummary> {
    const response = await apiClient.callFunction<KPISummary>("analytics", {
      method: "GET",
    });

    return response.data;
  }

  /**
   * Força atualização do cache de KPIs
   */
  async refreshCache(): Promise<KPISummary> {
    // A Edge Function já recalcula automaticamente
    return this.getSummary();
  }
}

export const analyticsService = new AnalyticsService();
