import { requireV3X402Release } from '../../x402/_lib/release';
import { staticV3Json, V3_PROTOCOL_VERSION, V3_SCHEMA_VERSION } from '../../_lib/http';

export function GET(): Response {
  const closed = requireV3X402Release();
  if (closed) return closed;
  const body = {
    schema: 'vaultfire.v3.solana.health.v1',
    schemaVersion: V3_SCHEMA_VERSION,
    protocolVersion: V3_PROTOCOL_VERSION,
    route: '/api/v3/solana/health',
    operational: false,
    readiness: 'source-only',
    source: {
      evidenceScope: 'source-only',
      inventoryAvailable: true,
      canonicalDispositionManifestAvailable: true,
      supportedCandidateCount: 6,
      redesignRequiredCount: 4,
      retiredCount: 5,
    },
    executable: {
      evidenceAvailable: false,
      deploymentAuthorized: false,
      deploymentMapAvailable: false,
      programAddressVerified: false,
      mainnetReadVerified: false,
    },
    rpcContacted: false,
    indexerContacted: false,
    paymentSettlementEnabled: false,
    protectedDecisionUse: 'prohibited',
    claims: { v3ProgramAddressVerified: false, mainnetReadVerified: false, bazaarIndexingVerified: false },
  } as const;
  return staticV3Json(body, assertV3SolanaHealth);
}

export function assertV3SolanaHealth(value: unknown): void {
  const body = value as Record<string, any>;
  if (
    !body || body.schema !== 'vaultfire.v3.solana.health.v1' ||
    body.schemaVersion !== V3_SCHEMA_VERSION || body.protocolVersion !== V3_PROTOCOL_VERSION ||
    body.route !== '/api/v3/solana/health' || body.operational !== false ||
    body.readiness !== 'source-only' || body.source?.evidenceScope !== 'source-only' ||
    body.source?.supportedCandidateCount !== 6 || body.source?.redesignRequiredCount !== 4 ||
    body.source?.retiredCount !== 5 || body.executable?.evidenceAvailable !== false ||
    body.executable?.deploymentAuthorized !== false || body.executable?.deploymentMapAvailable !== false ||
    body.executable?.programAddressVerified !== false || body.rpcContacted !== false ||
    body.indexerContacted !== false || body.paymentSettlementEnabled !== false ||
    body.protectedDecisionUse !== 'prohibited'
  ) throw new Error('invalid V3 Solana health document');
}
