import type {
  StatsSummary,
  FunnelConversion,
  RatingEntry,
  TrainerDetailedStats,
  StatsDateParams,
  StatsPeriod,
} from '../types/stats';
import { api } from './api';

export const statsService = {
  async getSummary(params?: StatsDateParams): Promise<StatsSummary> {
    return api.get<StatsSummary>('/stats/summary', {
      params: {
        dateFrom: params?.dateFrom,
        dateTo: params?.dateTo,
        trainerId: params?.trainerId,
      },
    });
  },

  async getFunnelConversion(params?: StatsDateParams): Promise<FunnelConversion> {
    return api.get<FunnelConversion>('/stats/funnel', {
      params: {
        dateFrom: params?.dateFrom,
        dateTo: params?.dateTo,
        trainerId: params?.trainerId,
      },
    });
  },

  async getRating(period?: StatsPeriod): Promise<RatingEntry[]> {
    return api.get<RatingEntry[]>('/stats/rating', {
      params: {
        period,
      },
    });
  },

  async getTrainerStats(
    trainerId: string,
    params?: Omit<StatsDateParams, 'trainerId'>,
  ): Promise<TrainerDetailedStats> {
    return api.get<TrainerDetailedStats>(`/stats/trainer/${trainerId}`, {
      params: {
        dateFrom: params?.dateFrom,
        dateTo: params?.dateTo,
      },
    });
  },
};
