/**
 * Plans API — proxies to platform-service /plans endpoint.
 *
 * GET  /api/settings/plans       → list plans
 */

import { NextRequest, NextResponse } from 'next/server';
import { requireAdmin } from '@/lib/auth-server';
import { listPlans } from '@/lib/platform-client';
import { getRequestProductId } from '@/lib/product-config';
import { logError } from '@/lib/logger';

export async function GET(req: NextRequest) {
  try {
    const admin = await requireAdmin(req);
    if (!admin) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });

    const result = await listPlans(getRequestProductId(req));
    return NextResponse.json(result);
  } catch (error) {
    logError('Plans list error', error);
    return NextResponse.json({ error: 'Failed to list plans' }, { status: 500 });
  }
}
