import { invalidV3Input, unavailableV3Read, V3_BYTES32 } from '../../../_lib/http';
import { requireV3X402Release } from '../../_lib/release';

export async function GET(
  _request: Request,
  context: { params: Promise<{ challengeId: string }> | { challengeId: string } },
): Promise<Response> {
  const closed = requireV3X402Release();
  if (closed) return closed;
  const { challengeId } = await context.params;
  if (!V3_BYTES32.test(challengeId)) return invalidV3Input('invalid_challenge_id', 'Challenge ID must be bytes32');
  return unavailableV3Read({
    route: '/api/v3/x402/challenges/:challengeId',
    resource: `/api/v3/x402/challenges/${challengeId}`,
    disposition: 'unavailable',
    readiness: 'adapter-unconfigured',
    code: 'v3_x402_challenge_unavailable',
    message: 'The canonical SDK marks x402.challenge unavailable and no V3 gateway deployment is configured',
  });
}
