import { apiClient } from '@/lib/api-client';
import type { CrmDashboardFilters, CrmDashboardResponse } from './types';

export async function getCrmDashboard(filters: CrmDashboardFilters): Promise<CrmDashboardResponse> {
  const searchParams = new URLSearchParams();

  if (filters.dateFrom) searchParams.set('dateFrom', filters.dateFrom);
  if (filters.dateTo) searchParams.set('dateTo', filters.dateTo);
  if (filters.branch) searchParams.set('branch', filters.branch);
  if (filters.salesman) searchParams.set('salesman', filters.salesman);
  if (filters.projectPartyRole) searchParams.set('projectPartyRole', filters.projectPartyRole);
  if (filters.productType) searchParams.set('productType', filters.productType);

  const query = searchParams.toString();
  return apiClient<CrmDashboardResponse>(`/crm/dashboard${query ? `?${query}` : ''}`);
}
