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

type AssetUrlFilters = {
  device_status?: string;
  company?: string;
  site_name?: string;
};

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

  if (filters.device_status) params.set('device_status', filters.device_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 || toDate) {
    params.set('date_filter_by', 'creation');
    if (fromDate) params.set('date_start', fromDate);
    if (toDate) params.set('date_end', toDate);
  }

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