import { SearchParams, SearchResult } from 'src/application/models/api/search';

// This will be set by the SearchProvider when it initializes
let searchServiceFunction: ((params: SearchParams) => Promise<SearchResult>) | null = null;

export const setSearchServiceFunction = (fn: (params: SearchParams) => Promise<SearchResult>) => {
  searchServiceFunction = fn;
};

export const getSearchServiceFunction = () => {
  if (!searchServiceFunction) {
    throw new Error(
      'Search service function not initialized. Make sure SearchProvider is mounted.',
    );
  }
  return searchServiceFunction;
};

export const clearSearchServiceFunction = () => {
  searchServiceFunction = null;
};
