import Stripe from 'stripe';
import { env } from '../config/env.js';

let stripe = null;

// A key is "real" if it's set, looks like a Stripe key, and isn't the .env placeholder.
function keyLooksReal(key) {
  return Boolean(key) && key.startsWith('sk_') && !key.includes('your_');
}

export function getStripe() {
  if (!keyLooksReal(env.stripeSecretKey)) {
    return null;
  }
  if (!stripe) {
    stripe = new Stripe(env.stripeSecretKey, { apiVersion: '2024-06-20' });
  }
  return stripe;
}

export function isStripeConfigured() {
  return keyLooksReal(env.stripeSecretKey);
}
