import type { BetterAuthClientPlugin } from "better-auth/client";
import { STRIPE_ERROR_CODES } from "./error-codes";
import type { StripePlan, stripe } from "./index";
import { PACKAGE_VERSION } from "./version";

export const stripeClient = <
	O extends {
		subscription: boolean;
	},
>(
	options?: O | undefined,
) => {
	return {
		id: "stripe-client",
		version: PACKAGE_VERSION,
		$InferServerPlugin: {} as ReturnType<
			typeof stripe<
				O["subscription"] extends true
					? {
							stripeClient: any;
							stripeWebhookSecret: string;
							subscription: {
								enabled: true;
								plans: StripePlan[];
							};
						}
					: {
							stripeClient: any;
							stripeWebhookSecret: string;
						}
			>
		>,
		pathMethods: {
			"/subscription/billing-portal": "POST",
			"/subscription/restore": "POST",
		},
		$ERROR_CODES: STRIPE_ERROR_CODES,
	} satisfies BetterAuthClientPlugin;
};
export * from "./error-codes";
