// 푸시 진단 — GET: 구독 현황 카운트 / POST: 본인 기기로 테스트 발송
import { NextResponse } from "next/server";
import { requireMomoUser } from "@/lib/momo-guard";
import { pushSubCounts, sendPush } from "@/lib/push";

export async function GET() {
  const r = await requireMomoUser();
  if (r instanceof NextResponse) return r;
  const counts = await pushSubCounts();
  return NextResponse.json({ success: true, ...counts });
}

export async function POST() {
  const r = await requireMomoUser();
  if (r instanceof NextResponse) return r;
  const userId = r.user.objid || r.user.userId;
  const res = await sendPush(
    { title: "테스트 알림 🔔", body: "이 알림이 보이면 푸시가 정상 동작합니다.", url: "/m/orders/new" },
    [userId]
  );
  return NextResponse.json({ success: true, ...res });
}
