import { invalidV3Input, strictV3Query, unavailableV3Read, V3_ADDRESS } from '../_lib/http';
import { requireV3X402Release } from '../x402/_lib/release';

export function GET(request: Request): Response {
  const closed = requireV3X402Release();
  if (closed) return closed;
  const query = strictV3Query(request, ['party']);
  const party = query?.get('party') ?? null;
  if (!party || !V3_ADDRESS.test(party)) {
    return invalidV3Input('invalid_party', 'A canonical 20-byte party address is required');
  }
  return unavailableV3Read({
    route: '/api/v3/bonds',
    resource: `/api/v3/bonds?party=${party}`,
    code: 'v3_bond_reader_unconfigured',
    message: 'Bond deployments and the party index adapter are not configured',
  });
}
