import type { CatalogProvider, ProductFilters } from "@/lib/headless/types";
import { medusaCatalogProvider } from "@/lib/headless/providers/medusa";
import { mockCatalogProvider } from "@/lib/headless/providers/mock";
import { shopifyCatalogProvider } from "@/lib/headless/providers/shopify";

function provider(): CatalogProvider {
  switch (process.env.HEADLESS_PROVIDER) {
    case "shopify": return shopifyCatalogProvider;
    case "medusa": return medusaCatalogProvider;
    default: return mockCatalogProvider;
  }
}

export async function getProducts(filters?: ProductFilters) {
  return provider().getProducts(filters);
}

export async function getProductBySlug(slug: string) {
  return provider().getProductBySlug(slug);
}

export async function searchProducts(query: string, limit?: number) {
  return provider().searchProducts(query, limit);
}
