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

export async function GET(request, { params }) {
  const { slug } = await params;
  const connection = await pool.getConnection();

  try {
    const [rows] = await pool.query(
      "SELECT * FROM silo_routes WHERE slug = ?",
      [slug]
    );

    if (rows.length === 0) {
      return NextResponse.json({
        success: false,
        error: 'Content not found',
        data: null
      }, { status: 404 });
    }

    return NextResponse.json({
      success: true,
      data: rows[0]
    }, { status: 200 });

  } catch (error) {
    console.error('Error fetching static page:', error);
    return NextResponse.json({
      success: false,
      error: error.message,
      data: null
    }, { status: 500 });

  } finally {
    connection.release();
  }
}