export const customQuerySerializer = (queryParams: any) => {
  const search: string[] = [];
  
  const serialize = (name: string, value: any) => {
    if (value === undefined || value === null) return;
    
    if (Array.isArray(value)) {
      value.forEach((v, i) => {
        serialize(`${name}[${i}]`, v);
      });
    } else if (typeof value === 'object' && value !== null && !(value instanceof Date)) {
      Object.entries(value).forEach(([key, v]) => {
        serialize(`${name}[${key}]`, v);
      });
    } else {
      const val = value instanceof Date ? value.toISOString() : String(value);
      search.push(`${encodeURIComponent(name)}=${encodeURIComponent(val)}`);
    }
  };

  if (queryParams && typeof queryParams === 'object') {
    for (const key in queryParams) {
      serialize(key, queryParams[key]);
    }
  }
  
  return search.join('&');
};
