import { BILLING_REGISTRY } from "@nextsparkjs/registries/billing-registry";
import { StripeGateway } from "./stripe.js";
import { PolarGateway } from "./polar.js";
let gatewayInstance = null;
function getBillingGateway() {
  if (!gatewayInstance) {
    const provider = BILLING_REGISTRY.provider;
    switch (provider) {
      case "stripe":
        gatewayInstance = new StripeGateway();
        break;
      case "polar":
        gatewayInstance = new PolarGateway();
        break;
      // Future providers:
      // case 'paddle': { ... }
      // case 'lemonsqueezy': { ... }
      // case 'mercadopago': { ... }
      default:
        throw new Error(
          `Unsupported billing provider: "${provider}". Supported providers: stripe, polar. Check your billing.config.ts provider setting.`
        );
    }
  }
  return gatewayInstance;
}
function getBillingResourceHints() {
  try {
    return getBillingGateway().getResourceHintDomains();
  } catch {
    return { preconnect: [], dnsPrefetch: [] };
  }
}
function resetBillingGateway() {
  gatewayInstance = null;
}
export {
  getBillingGateway,
  getBillingResourceHints,
  resetBillingGateway
};
