/* eslint-disable @typescript-eslint/no-explicit-any */
import { api } from "./Api"; // Adjust the import path to your api utility

export async function getMasterList(listType: string, params?: any) {
  console.log('Master list params:', params);
  const url = `/user/master/${listType}/list`;
  
  // Add search parameter if not provided
  if (params) {
    if (!params.search) {
      params.search = "";
    }
  } else {
    params = { search: "" };
  }

  // Pass params directly in the URL instead of nesting them
  const queryString = Object.entries(params)
    .map(([key, value]) => `${key}=${value}`)
    .join('&');
  
  const fullUrl = `${url}?${queryString}`;
  const [, response] = await api.get(fullUrl, false);
  return response;
}

export async function getList(apiUrl: string, params?: any) {
  const url = apiUrl;
  
  if (params) {
    if (!params.search) {
      params.search = "";
    }
  } else {
    params = { search: "" };
  }

  // Pass params directly in the URL instead of nesting them
  const queryString = Object.entries(params)
    .map(([key, value]) => `${key}=${value}`)
    .join('&');
  
  const fullUrl = `${url}?${queryString}`;
  const [, response] = await api.get(fullUrl, false);
  return response;
}