// 기준 명세표 (공급자 정보) 목록 — admin
import { NextResponse } from "next/server";
import { queryRows } from "@/lib/db";
import { requireMomoAdmin } from "@/lib/momo-guard";

export async function POST() {
  const g = await requireMomoAdmin();
  if (g instanceof NextResponse) return g;
  const rows = await queryRows(
    `SELECT code         AS "CODE",
            name         AS "NAME",
            bank_account AS "BANK_ACCOUNT",
            phone        AS "PHONE",
            email        AS "EMAIL",
            ceo_name     AS "CEO_NAME",
            biz_no       AS "BIZ_NO",
            address      AS "ADDRESS",
            COALESCE(is_default, 'N') AS "IS_DEFAULT",
            COALESCE(sort_order, 0)   AS "SORT_ORDER"
     FROM momo_statement_branches
     WHERE COALESCE(is_del,'N') != 'Y'
     ORDER BY sort_order ASC, code ASC`
  );
  return NextResponse.json({ RESULTLIST: rows, TOTAL_CNT: rows.length });
}
