import { z } from 'zod';

const envSchema = z.object({
  PORT: z.coerce.number().default(4003),
  HOST: z.string().default('0.0.0.0'),
  NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
  CORS_ORIGIN: z.string().optional(),
  SERVICE_NAME: z.string().default('platform-service'),
  COSMOS_ENDPOINT: z.string().min(1, 'COSMOS_ENDPOINT is required'),
  COSMOS_KEY: z.string().min(1, 'COSMOS_KEY is required'),
  COSMOS_DATABASE: z.string().default('lysnrai'),
  JWT_SECRET: z.string().min(1, 'JWT_SECRET is required'),
  AZURE_BLOB_CONNECTION_STRING: z.string().optional(),
  AZURE_BLOB_ACCOUNT_NAME: z.string().optional(),
  AZURE_BLOB_ACCOUNT_KEY: z.string().optional(),
  RATE_LIMIT_CONFIG_JSON: z.string().optional(),
  // ── Growth (merged) ──
  WEBHOOK_INVITATION_REDEEMED_URL: z.string().optional(),
  WEBHOOK_REFERRAL_STATUS_URL: z.string().optional(),
  // ── AI Diagnostics ──
  AZURE_OPENAI_KEY: z.string().optional(),
  AZURE_OPENAI_ENDPOINT: z.string().optional(),
  // ── Billing (merged) ──
  STRIPE_SECRET_KEY: z.string().optional(),
  STRIPE_WEBHOOK_SECRET: z.string().optional(),
  STRIPE_PRICE_PRO: z.string().optional(),
  STRIPE_PRICE_ENTERPRISE: z.string().optional(),
  BACKEND_URL: z.string().default('http://localhost:8000'),
  PLAN_LIMITS_JSON: z.string().optional(),
  USAGE_WARN_THRESHOLD: z.coerce.number().default(0.8),
});

export const config = envSchema.parse(process.env);
