import { NextResponse } from "next/server";

import { serializeUnit } from "@/features/units/lib/serialize-unit";
import { ensureFixedUnits, getFixedUnitLockMessage } from "@/features/units/lib/fixed-units";
import { requireApiAccess } from "@/lib/authorization";

export async function GET(request: Request) {
  const auth = requireApiAccess(request);
  if (!auth.ok) return auth.response;
  const data = await ensureFixedUnits();
  return NextResponse.json({ data: data.map(serializeUnit) });
}

export async function POST(request: Request) {
  const auth = requireApiAccess(request);
  if (!auth.ok) return auth.response;
  return NextResponse.json({ message: getFixedUnitLockMessage() }, { status: 403 });
}
