import Stripe from "stripe";
import { env } from "@/lib/env";

const stripeSecretKey = env.stripeSecretKey;

let stripeClient: Stripe | null = null;

export function isStripeConfigured() {
  return Boolean(stripeSecretKey);
}

export function getStripeServerClient() {
  if (!stripeSecretKey) {
    throw new Error("STRIPE_SECRET_KEY is missing.");
  }

  if (!stripeClient) {
    stripeClient = new Stripe(stripeSecretKey);
  }

  return stripeClient;
}
