// 푸시 공지 목록 (admin) — 최근 작성한 공지
import { NextResponse } from "next/server";
import { queryRows } from "@/lib/db";
import { requireMomoAdmin } from "@/lib/momo-guard";
import { ensureNoticesTable } from "@/lib/notices";

export async function POST() {
  const g = await requireMomoAdmin();
  if (g instanceof NextResponse) return g;
  await ensureNoticesTable();
  const rows = await queryRows(
    `SELECT objid AS "OBJID", title AS "TITLE", body AS "BODY",
            image_url AS "IMAGE_URL", url AS "URL",
            TO_CHAR(regdate, 'YYYY-MM-DD HH24:MI') AS "REGDATE",
            regid AS "REGID", sent_count AS "SENT_COUNT"
       FROM momo_notices
      WHERE COALESCE(is_del,'N') != 'Y'
      ORDER BY regdate DESC
      LIMIT 100`
  );
  return NextResponse.json({ RESULTLIST: rows, TOTAL_CNT: rows.length });
}
