import { NextRequest, NextResponse } from 'next/server';
import pool from '../../../../../lib/db/db';


export async function GET(request: NextRequest, {params}) {

    const connection = await pool.getConnection();

    const {id} = await params;
    
    try{
    
        const response = await fetch(`https://crm-universitiespage.com/reactapis/api/job-details/${id}`, {
            method: "GET",
            headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${process.env.CRM_API_KEY}`,
            },
        });

        console.log(response);

        const data = await response.json();

        if (data?.status_code !== 200) {
            return NextResponse.json(
            {
                message: "Failed to submit your form. Please try again later.",
                success: false
            },
            {
                status: 500
            }
            );
        }

        return NextResponse.json(
            {
                data: data.data,
                success: true
            },
            {
                status: 200
            }
        );
        
    } catch (error) {
    console.error('Database error:', error);
    return Response.json(
        {
        error: 'Failed to fetch jobs',
        details: {
            message: error.message,
            code: error.code,
            meta: error.meta,
        },
        },
        { status: 500 }
    );
    }

    
}