import { NextResponse } from 'next/server';
import { withErrorHandler } from '@server/middleware/withErrorHandler';
import { withAuth, AuthedRequest } from '@server/middleware/withAuth';
import { listPlans } from '@server/services/billing.service';

export const GET = withErrorHandler(
  withAuth(async (req: AuthedRequest) => {
    const url = new URL(req.url);
    const currency = url.searchParams.get('currency') ?? undefined;
    const plans = await listPlans(currency);
    return NextResponse.json({ plans });
  })
);
