import { RowDataPacket } from "mysql2";
import pool from "../../../../lib/db/db";
import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {

    try{
        const [rows] = await pool.query<RowDataPacket[]>("SELECT * FROM countries");

        if(rows.length === 0) {
            return NextResponse.json({ error: "No countries found" }, { status: 404 });
        }

        return NextResponse.json({data:rows}, { status: 200 });
    } catch (error) {
        console.error("Error fetching countries:", error);
        return NextResponse.json({ error: "Failed to fetch countries" }, { status: 500 });
    }

}