import Stripe from "stripe";
import { loadSystemConfig } from "./system-config";

let stripe: Stripe | null = null;

export async function getStripe() {
  if (stripe) return stripe;
  const cfg = await loadSystemConfig();
  const key = cfg.stripe?.secretKey || process.env.STRIPE_SECRET_KEY;
  if (!cfg.stripe?.enabled || !key) return null;
  stripe = new Stripe(key, { apiVersion: "2024-06-20" as any });
  return stripe;
}
