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

// -------------------- GET --------------------
export async function POST(req: NextRequest) {

    const connection = await pool.getConnection();

    try {

        const [getConsultantCount] = await connection.query<RowDataPacket[]>("SELECT COUNT(*) as totalItems FROM users WHERE user_type = ?", ['consultant'])

        if(getConsultantCount[0].totalItems === 0){
            return NextResponse.json(
                {
                    message: "No Count",
                    totalItems : 0
                },
                {
                    status: 404
                }
            )
        }

        return NextResponse.json(
            {
                message: "Total Count",
                totalItems : getConsultantCount[0].totalItems
            },
            {
                status: 200
            }
        )

    } catch (error){
        return NextResponse.json(
            {
                message: "Error Calculating the Consultant Count",
                totalItems : 0
            },
            {
                status: 500
            }
        )
    } finally{
        connection.release();
    }

}   