import { NextResponse } from 'next/server';
import pool from '@/lib/db';
import { RowDataPacket } from 'mysql2';

export async function GET() {
    try {
        const [categories] = await pool.query<RowDataPacket[]>(
            'SELECT * FROM categories ORDER BY name ASC'
        );

        return NextResponse.json(categories);
    } catch (error) {
        console.error('Get categories error:', error);
        return NextResponse.json(
            { error: 'Internal server error' },
            { status: 500 }
        );
    }
}
