import { envTrim } from "./environment";

/**
 * RevenueCat server configuration (secret key never exposed to clients).
 * @see https://www.revenuecat.com/docs/api-v2
 */
export const revenuecatConfig = {
  secretKey: envTrim("REVENUECAT_SECRET_KEY") ?? "",
  baseUrl: (envTrim("REVENUECAT_BASE_URL") ?? "https://api.revenuecat.com/v2").replace(
    /\/+$/,
    "",
  ),
  projectId: envTrim("REVENUECAT_PROJECT_ID") ?? "",
  webhookSecret: envTrim("REVENUECAT_WEBHOOK_SECRET") ?? "",
  premiumEntitlement: envTrim("REVENUECAT_PREMIUM_ENTITLEMENT") ?? "premium",
  familyEntitlement: envTrim("REVENUECAT_FAMILY_ENTITLEMENT") ?? "family",
};

export function isRevenueCatApiConfigured(): boolean {
  return Boolean(revenuecatConfig.secretKey && revenuecatConfig.projectId);
}
