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

export async function GET(request: Request) {
  try {
    // Simple query to get all countries
    const query = "SELECT id, full_name FROM authors WHERE status = 'active' ";
    
    const [authors] = await pool.query(query);
    
    return NextResponse.json({
      success: true,
      data: authors,
      count: Array.isArray(authors) ? authors.length : 0
    });
    
  } catch (error) {
    console.error('Error fetching authors:', error);
    return NextResponse.json(
      {
        success: false,
        message: 'Failed to fetch countries',
        error: error instanceof Error ? error.message : 'Unknown error'
      },
      { status: 500 }
    );
  }
}