// src/lib/billing/stripe-client.ts — one place to build the Stripe SDK client.
// Factored out so the God-Mode billing actions (and tests) have a single,
// mock-friendly seam. `getStripe()` THROWS a clear "Stripe not configured"
// error when the secret key is missing, so every Stripe-API call degrades
// gracefully (the action refuses cleanly instead of constructing a broken
// client). Read paths use `isStripeConfigured()` to disable UI up front.
import "server-only";
import Stripe from "stripe";
import { env } from "@/env";

/** True when the Stripe secret key is present (the minimum to call the API). */
export function isStripeConfigured(): boolean {
  return Boolean(env.STRIPE_SECRET_KEY);
}

/** Build a Stripe client, or throw a clear error when Stripe isn't configured. */
export function getStripe(): Stripe {
  if (!env.STRIPE_SECRET_KEY) {
    throw new Error("Stripe is not configured");
  }
  return new Stripe(env.STRIPE_SECRET_KEY);
}
