import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
    try {
        const token = request.headers.get('authorization');

        if (!token) {
            return NextResponse.json(
                { error: 'Token não fornecido' },
                { status: 401 }
            );
        }

        const response = await fetch('http://aggios-backend:8080/api/portal/leads', {
            headers: {
                'Authorization': token,
            },
        });

        const data = await response.json();

        if (!response.ok) {
            return NextResponse.json(data, { status: response.status });
        }

        return NextResponse.json(data);
    } catch (error) {
        console.error('Leads fetch error:', error);
        return NextResponse.json(
            { error: 'Erro ao buscar leads' },
            { status: 500 }
        );
    }
}
