import { NextRequest, NextResponse } from 'next/server';
import { requireAuth } from '@/shared/auth/guards';
import { checkEntitlement } from '@/shared/billing/entitlements';

// --- ASA GENERATED START ---
// Route handler for billing/check-limits slice.
// Returns current plan entitlements and whether user can access a specific feature.
// Security: requires authenticated user.
// --- ASA GENERATED END ---

// --- USER CODE START ---

export async function GET(request: NextRequest): Promise<NextResponse> {
  try {
    const { user, response } = await requireAuth(request);
    if (response) return response;

    const url = new URL(request.url);
    const feature = url.searchParams.get('feature');

    const result = await checkEntitlement(user!.id, feature ?? undefined);

    return NextResponse.json(result);
  } catch (err) {
    console.error('[billing/check-limits] Error:', err);
    return NextResponse.json(
      { plan: 'free', entitlements: {}, can_access: false },
      { status: 500 },
    );
  }
}

// --- USER CODE END ---
