/**
 * GET /x402-monetize.json
 *
 * Public x402 service manifest — discovered by the Coinbase x402 Bazaar,
 * agentic.market, and any other x402-aware crawler that fetches the
 * standard /x402-monetize.json path.
 *
 * Built dynamically from the comprehensive endpoint catalog in
 * /.well-known/x402.json so this manifest never falls out of sync with
 * the real list of paywalled routes. Every route listed here returns
 * a real HTTP 402 challenge if called without a valid x402 payment.
 *
 * Schema: https://x402.org/schemas/monetize-service.json
 */
import { NextResponse } from 'next/server';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

export const dynamic = 'force-static';
export const revalidate = 300;

interface CatalogEndpoint {
  path: string;
  method: string;
  description?: string;
  price?: string;
}

interface CatalogShape {
  endpoints: CatalogEndpoint[];
}

function loadCatalog(): CatalogShape {
  const p = join(process.cwd(), 'public', '.well-known', 'x402.json');
  const raw = readFileSync(p, 'utf8');
  return JSON.parse(raw);
}

export async function GET() {
  return NextResponse.json(
    {
      error: 'x402 monetization discovery is disabled pending release-readiness evidence',
      code: 'x402_release_gate_closed',
    },
    { status: 503, headers: { 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' } },
  );
}
