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

export async function GET() {
  let connection;
  
  try {
    connection = await pool.getConnection();

    const query = `
      SELECT 
        id,
        name,
        slug
      FROM silo_routes 
      ORDER BY name ASC
    `;
    
    const [siloRoutes] = await connection.query(query);

    return NextResponse.json({
      success: true,
      data: siloRoutes
    });
  } catch (error) {
    console.error("GET /silo-routes/list error:", error);
    return NextResponse.json(
      { 
        success: false,
        error: "Failed to fetch silo routes", 
        details: error.message 
      },
      { status: 500 }
    );
  } finally {
    if (connection) {
      connection.release();
    }
  }
}