/**
 * GET /api/stripe/config — Returns Stripe configuration for admin dashboard.
 * Includes mode, configured status, product/price IDs, and account info.
 * Safe to expose — no secret keys included.
 */

import { NextResponse } from 'next/server';

function getStripeMode(): 'test' | 'live' | 'dev' {
  const key = process.env.STRIPE_SECRET_KEY;
  if (!key) return 'dev';
  if (key.startsWith('sk_test_')) return 'test';
  if (key.startsWith('sk_live_')) return 'live';
  return 'dev';
}

export async function GET() {
  const mode = getStripeMode();
  const key = process.env.STRIPE_SECRET_KEY || '';

  return NextResponse.json({
    mode,
    configured: !!key && !key.includes('placeholder'),
    publishableKey: process.env.STRIPE_PUBLISHABLE_KEY
      ? `${process.env.STRIPE_PUBLISHABLE_KEY.slice(0, 12)}...`
      : null,
    priceIds: {
      pro: process.env.STRIPE_PRICE_PRO || null,
      enterprise: process.env.STRIPE_PRICE_ENTERPRISE || null,
    },
    webhookConfigured: !!process.env.STRIPE_WEBHOOK_SECRET,
    billingServiceUrl: process.env.PLATFORM_SERVICE_URL || 'http://localhost:4003',
  });
}
