import type { DashboardLocationFilters } from './hospitalUtils';

type MaintenanceUrlFilters = {
  assignee?: string;
  status?: string;
  company?: string;
  site_name?: string;
};

export function buildMaintenanceUrl(
  filters: MaintenanceUrlFilters,
  fromDate?: string,
  toDate?: string,
  locationFilters?: DashboardLocationFilters
): string {
  const params = new URLSearchParams();

  if (filters.assignee) params.set('assignee', filters.assignee);
  if (filters.status) params.set('status', filters.status);

  if (filters.company || locationFilters?.company) {
    params.set('company', filters.company || locationFilters?.company || '');
  }
  if (filters.site_name || locationFilters?.site_name) {
    params.set('site_name', filters.site_name || locationFilters?.site_name || '');
  }

  if (fromDate) params.set('date_start', fromDate);
  if (toDate) params.set('date_end', toDate);

  const qs = params.toString();
  return `/maintenance${qs ? `?${qs}` : ''}`;
}
