/**
 * API для статистики доходов ментора
 */

import apiClient from '@/lib/api-client';

export interface IncomeStats {
  period: 'day' | 'week' | 'month' | 'range';
  start_date: string;
  end_date: string;
  summary: {
    total_income: number;
    total_lessons: number;
    average_lesson_price: number;
  };
  chart_data: { date: string; income: number; lessons: number }[];
  top_lessons: {
    lesson_title: string;
    subject?: string;
    target_name: string;
    is_group: boolean;
    lessons_count: number;
    total_income: number;
  }[];
}

export async function getIncomeStats(params?: {
  period?: 'day' | 'week' | 'month' | 'range';
  start_date?: string;
  end_date?: string;
}): Promise<IncomeStats> {
  const queryParams = new URLSearchParams();
  if (params?.period) queryParams.append('period', params.period);
  if (params?.start_date) queryParams.append('start_date', params.start_date);
  if (params?.end_date) queryParams.append('end_date', params.end_date);
  const q = queryParams.toString();
  const url = `/mentor/income${q ? `?${q}` : ''}`;
  const response = await apiClient.get<IncomeStats>(url);
  return response.data;
}
