import { NextRequest, NextResponse } from "next/server";
import { queryRows } from "@/lib/db";
import { getSession } from "@/lib/session";

// 메뉴관리 목록 조회
export async function POST(request: NextRequest) {
  const user = await getSession();
  if (!user) return NextResponse.json({ success: false }, { status: 401 });

  const sql = `
    SELECT MI.objid::text AS "OBJID", MI.menu_name_kor AS "MENU_NAME_KOR",
      MI.menu_name_eng AS "MENU_NAME_ENG", MI.menu_url AS "MENU_URL",
      MI.parent_obj_id::text AS "PARENT_OBJ_ID", MI.seq::text AS "SEQ",
      COALESCE(MI.status, '') AS "STATUS"
    FROM menu_info MI
    ORDER BY MI.parent_obj_id, MI.seq
  `;

  const rows = await queryRows(sql);
  return NextResponse.json({ RESULTLIST: rows, TOTAL_CNT: rows.length });
}
