import { z } from "zod";
const shippingProviders = /* @__PURE__ */ new Map();
const paymentProviders = /* @__PURE__ */ new Map();
const providerSettingsSchema = z.record(z.string(), z.unknown()).optional();
function registerShippingProvider(provider) {
  if (!provider.key) return () => {
  };
  const normalizedKey = provider.key.trim();
  if (!normalizedKey) return () => {
  };
  shippingProviders.set(normalizedKey, { ...provider, key: normalizedKey });
  return () => {
    shippingProviders.delete(provider.key);
  };
}
function registerPaymentProvider(provider) {
  if (!provider.key) return () => {
  };
  const normalizedKey = provider.key.trim();
  if (!normalizedKey) return () => {
  };
  paymentProviders.set(normalizedKey, { ...provider, key: normalizedKey });
  return () => {
    paymentProviders.delete(provider.key);
  };
}
function listShippingProviders() {
  return Array.from(shippingProviders.values());
}
function listPaymentProviders() {
  return Array.from(paymentProviders.values());
}
function getShippingProvider(key) {
  if (!key) return null;
  return shippingProviders.get(key) ?? null;
}
function getPaymentProvider(key) {
  if (!key) return null;
  return paymentProviders.get(key) ?? null;
}
function normalizeProviderSettings(kind, providerKey, settings) {
  const parsed = providerSettingsSchema.safeParse(settings);
  if (!providerKey || !parsed.success) return parsed.success ? parsed.data ?? null : null;
  const provider = kind === "shipping" ? getShippingProvider(providerKey) : getPaymentProvider(providerKey);
  if (!provider || !provider.settings?.schema) return parsed.data ?? null;
  const normalized = provider.settings.schema.safeParse(parsed.data ?? {});
  if (!normalized.success) {
    return parsed.data ?? null;
  }
  return normalized.data ?? null;
}
export {
  getPaymentProvider,
  getShippingProvider,
  listPaymentProviders,
  listShippingProviders,
  normalizeProviderSettings,
  registerPaymentProvider,
  registerShippingProvider
};
//# sourceMappingURL=registry.js.map
