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

interface BankRow extends RowDataPacket {
  bankcode: string;
  bankname: string;
}

interface AccountTypeRow extends RowDataPacket {
  accounttypecode: string;
  accounttypedesc: string;
}

export async function GET() {
  try {
    // Get all banks
    const [banks] = await pool.query<BankRow[]>('SELECT bankcode, bankname FROM banks');
    // Get all account types
    const [accounttypes] = await pool.query<AccountTypeRow[]>('SELECT accounttypecode, accounttypedesc FROM accounttypes');
    return NextResponse.json({ banks, accounttypes });
  } catch (error) {
    console.error('Error fetching filters:', error);
    return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
  }
}