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

export async function getMasterOptions(
  filters: MasterOptionsFilters
): Promise<MasterOptionsResponse> {
  const searchParams = new URLSearchParams();

  if (filters.page) searchParams.set('page', String(filters.page));
  if (filters.limit) searchParams.set('limit', String(filters.limit));
  if (filters.search) searchParams.set('search', filters.search);
  if (filters.category) searchParams.set('category', filters.category);
  if (filters.sort) searchParams.set('sort', filters.sort);

  const query = searchParams.toString();

  return apiClient<MasterOptionsResponse>(`/foundation/master-options${query ? `?${query}` : ''}`);
}
