import Stripe from "stripe";

let _stripe: Stripe | null = null;

export function getStripe(): Stripe {
  if (!_stripe) {
    const key = process.env.STRIPE_SECRET_KEY;
    if (!key) throw new Error("STRIPE_SECRET_KEY is not set");
    _stripe = new Stripe(key, { apiVersion: "2026-01-28.clover" });
  }
  return _stripe;
}

export const TIER_CONFIG = {
  FREE: {
    name: "Free",
    sessionsLimit: 20,
    period: "day",
    price: 0,
  },
  STARTER: {
    name: "Starter",
    priceId: process.env.STRIPE_STARTER_PRICE_ID!,
    sessionsLimit: 1000,
    period: "month",
    price: 5,
  },
  PRO: {
    name: "Pro",
    priceId: process.env.STRIPE_PRO_PRICE_ID!,
    sessionsLimit: 100000,
    period: "month",
    price: 20,
  },
} as const;
