import { NextResponse } from "next/server";
import { getPool } from "@/lib/db";

export async function GET() {
  try {
    const pool = getPool();
    const [rows] = await pool.query(
      "SELECT today_jalali FROM jalali_dates LIMIT 1"
    ) as unknown as [any[], any];
    const result = rows[0];
    if (!result) {
      return NextResponse.json({ error: "No date found" }, { status: 404 });
    }
    return NextResponse.json({ today_jalali: result.today_jalali });
  } catch (err) {
    console.error("Error fetching today_jalali:", err);
    return NextResponse.json(
      { error: "Internal server error" },
      { status: 500 }
    );
  }
}
