import { NextResponse } from "next/server";
import { queryRows } from "@/lib/db";
import { requireMomoUser } from "@/lib/momo-guard";

export async function POST() {
  const r = await requireMomoUser();
  if (r instanceof NextResponse) return r;
  const rows = await queryRows(
    `SELECT objid AS "OBJID", wh_code AS "WH_CODE", wh_name AS "WH_NAME",
            location AS "LOCATION", wh_type AS "WH_TYPE",
            TO_CHAR(regdate, 'YYYY-MM-DD') AS "REGDATE"
     FROM momo_warehouses
     WHERE COALESCE(is_del,'N') != 'Y'
     ORDER BY wh_code ASC`
  );
  return NextResponse.json({ RESULTLIST: rows, TOTAL_CNT: rows.length });
}
