/**
 * Client-safe Stripe price lookup
 *
 * Reads directly from JSON config — no Redis caching, no server-only deps.
 * Use this in client components. Use lib/stripe-prices.ts in server components/routes.
 */
import multiCurrencyConfig from '@/lib/config/stripe-prices-multi-currency.json';

type MultiCurrencyConfig = typeof multiCurrencyConfig;
type AvailableCurrency = keyof MultiCurrencyConfig['currencies'];

/**
 * Get Stripe price ID for a tier, billing period, and currency.
 * Reads from static JSON config — safe to call from client components.
 */
export function getStripePriceId(
  tierId: string,
  billingPeriod: 'monthly' | 'yearly',
  currency: string = 'QAR'
): string | null {
  const currencyUpper = currency.toUpperCase();

  if (!(currencyUpper in multiCurrencyConfig.currencies)) {
    return null;
  }

  const currencyConfig = multiCurrencyConfig.currencies[currencyUpper as AvailableCurrency];
  if (!currencyConfig) return null;

  const tierConfig = currencyConfig[tierId as keyof typeof currencyConfig];
  if (!tierConfig) return null;

  return billingPeriod === 'monthly' ? tierConfig.monthly : tierConfig.yearly;
}
