// Stripe shim for CF Workers
// Wraps the real Stripe constructor to auto-inject fetch HTTP client
// The real Stripe package is loaded directly (not through alias) via the
// esbuild plugin that excludes this file from the stripe alias.

// @ts-ignore — this import is resolved by esbuild to the real stripe package
import OriginalStripe from '__real_stripe__';

// Wrap constructor to inject fetch HTTP client
function StripeWrapper(this: any, apiKey: string, config: any = {}) {
  const cfConfig = {
    ...config,
    httpClient: (OriginalStripe as any).createFetchHttpClient(),
  };
  return new (OriginalStripe as any)(apiKey, cfConfig);
}

// Copy all static properties
Object.keys(OriginalStripe).forEach((key) => {
  (StripeWrapper as any)[key] = (OriginalStripe as any)[key];
});
Object.setPrototypeOf(StripeWrapper, OriginalStripe);
Object.setPrototypeOf(StripeWrapper.prototype, (OriginalStripe as any).prototype);

// Also copy createFetchHttpClient for direct usage
(StripeWrapper as any).createFetchHttpClient = (OriginalStripe as any).createFetchHttpClient;

export default StripeWrapper;
export { StripeWrapper as Stripe };
