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

// 상위 메뉴 (헤더 탑 메뉴) 조회
export async function GET() {
  const user = await getSession();
  if (!user) {
    return NextResponse.json({ success: false }, { status: 401 });
  }

  const rows = await queryRows(
    `SELECT MI.OBJID::text AS "OBJID", MI.MENU_NAME_KOR AS "MENU_NAME_KOR",
            MI.MENU_NAME_ENG, MI.MENU_URL, MI.SEQ
     FROM MENU_INFO MI
     WHERE MI.PARENT_OBJ_ID = 0
       AND COALESCE(MI.STATUS, '') != 'DELETED'
     ORDER BY MI.SEQ`,
    []
  );

  return NextResponse.json({ success: true, menus: rows });
}
