import { apiClient } from './client';
import type { TodaySummaryResponse } from '@/types/today';
import type { TodayChartPeriods } from '@/components/today/chart-periods';

export interface TodaySummaryParams {
  from: string;
  to: string;
  utcOffsetMinutes?: number;
  chartPeriods?: TodayChartPeriods;
}

function chartPeriodQuery(periods?: TodayChartPeriods) {
  if (!periods) return {};
  return {
    appointmentsWeekPeriod: periods.appointmentsWeekAll,
    appointmentsWeekMinePeriod: periods.appointmentsWeekMine,
    labTaskActivityPeriod: periods.labTaskActivity,
    casesDuePeriod: periods.casesDue,
    treatmentMixPeriod: periods.treatmentMix,
    casePartnersPeriod: periods.casePartners,
    efficiencyPeriod: periods.efficiency,
  };
}

export const todayApi = {
  summary: async (params: TodaySummaryParams): Promise<TodaySummaryResponse> => {
    const { chartPeriods, ...range } = params;
    const response = await apiClient.get('/today/summary', {
      params: { ...range, ...chartPeriodQuery(chartPeriods) },
    });
    return response.data;
  },
};
