import { ProductRetrievalParams, ProductRetrievalResult } from './types';

// This will be set by the ProductRetrievalProvider when it initializes
const productRetrievalAdapter: {
  fn: ((params: ProductRetrievalParams) => Promise<ProductRetrievalResult>) | null;
} = { fn: null };

export const setProductRetrievalFunction = (
  fn: (params: ProductRetrievalParams) => Promise<ProductRetrievalResult>,
) => {
  productRetrievalAdapter.fn = fn;
};

export const getProductRetrievalFunction = () => {
  if (!productRetrievalAdapter.fn) {
    throw new Error(
      'Product retrieval function not initialized. Make sure ProductRetrievalProvider is mounted.',
    );
  }
  return productRetrievalAdapter.fn;
};
