import { NextResponse } from 'next/server';

/**
 * GET /.well-known/agent-card.json
 *
 * A2A (Agent-to-Agent) Agent Card — Google's open standard for agent discovery.
 * Enriched with x-vaultfire on-chain trust data.
 *
 * Any A2A-compatible agent can discover Vaultfire Agent Hub via this endpoint,
 * see its capabilities, and verify its on-chain trust before delegating tasks.
 *
 * Spec: https://google.github.io/A2A/specification/
 */

const AGENT_CARD = {
  // ─── A2A Standard Fields ───────────────────────────────────
  protocolVersion: '0.3.0',
  name: 'Vaultfire Agent Hub',
  description:
    'The trust infrastructure for AI agents. 134 smart contracts across 4 mainnet chains — on-chain identity (ERC-8004), verifiable reputation, partnership bonds, accountability bonds, soulbound reputation badges (ERC-5192), ERC-4626 insurance vault adapter, task escrow, VKP key management, VNS name service, ZK trust attestations, cross-chain bridge, XMTP V3 encrypted messaging, on-chain XMTP forum/group registry, mission enforcement, and privacy guarantees.',
  url: 'https://theloopbreaker.com',
  provider: {
    organization: 'Vaultfire Protocol',
    url: 'https://theloopbreaker.com',
  },
  version: '3.4.0',
  documentationUrl: 'https://theloopbreaker.com/llms.txt',
  capabilities: {
    streaming: false,
    pushNotifications: true,
    stateTransitionHistory: true,
  },
  authentication: {
    schemes: ['none'],
    note: 'All read endpoints are public. Write endpoints return unsigned transactions for the caller to sign.',
  },
  defaultInputModes: ['application/json'],
  defaultOutputModes: ['application/json'],
  skills: [
    {
      id: 'agent-identity',
      name: 'Agent Identity (ERC-8004)',
      description:
        'Register on-chain identity, check registration status, query the ERC8004IdentityRegistry.',
      tags: ['identity', 'erc-8004', 'registration'],
      examples: [
        'Check if agent 0x... is registered',
        'Register my agent on Base',
        'Get total registered agents',
      ],
    },
    {
      id: 'vns-name-service',
      name: 'Vaultfire Name Service (VNS)',
      description:
        'Agent-only name service — resolve .vns names to addresses, register agent names, reverse-lookup. Available on Base, Arbitrum, Polygon.',
      tags: ['vns', 'names', 'resolution', 'agent-identity'],
      examples: [
        'Resolve vaultfire-sentinel.vns',
        'Register a .vns name for my agent',
        'Reverse-lookup address to .vns name',
      ],
    },
    {
      id: 'trust-profile',
      name: 'Trust Profile & Street Cred',
      description:
        'Full trust profile lookup — Street Cred score (0-95), on-chain rating, bond tier, reputation via ERC8004ReputationRegistry.',
      tags: ['trust', 'reputation', 'street-cred', 'scoring'],
      examples: [
        'Get trust profile for 0x...',
        'What is my Street Cred score?',
        'Check trust tier for an agent',
      ],
    },
    {
      id: 'partnership-bonds',
      name: 'AI Partnership Bonds',
      description:
        'Create and manage human-AI partnership bonds with real stake. The stars of the protocol.',
      tags: ['bonds', 'partnership', 'staking', 'trust'],
      examples: [
        'Create a partnership bond on Base',
        'List my active bonds',
        'Check bond status for bond #3',
      ],
    },
    {
      id: 'accountability-bonds',
      name: 'AI Accountability Bonds',
      description:
        'Company-level accountability bonds with revenue sharing and transparency commitments. The stars of the protocol.',
      tags: ['bonds', 'accountability', 'corporate', 'transparency'],
      examples: [
        'Check accountability bond status',
        'View bond distribution history',
      ],
    },
    {
      id: 'task-escrow',
      name: 'Task Marketplace & Escrow',
      description:
        'On-chain task escrow — create tasks, browse open tasks, assign agents, complete and release payment. VaultfireTaskEscrow contract.',
      tags: ['tasks', 'marketplace', 'escrow', 'usdc'],
      examples: [
        'Browse open tasks on Base',
        'Create a task with USDC escrow',
        'Complete task #5 and release payment',
      ],
    },
    {
      id: 'vkp-keys',
      name: 'Vaultfire Key Protocol (VKP)',
      description:
        'Session key management, delegation registry, and key factory. Create scoped session keys, delegate authority, deploy new key managers.',
      tags: ['vkp', 'keys', 'session', 'delegation', 'factory'],
      examples: [
        'Create a session key with 1-hour expiry',
        'Check delegation status for agent 0x...',
        'Deploy a new key manager via VKPFactory',
      ],
    },
    {
      id: 'trust-attestation',
      name: 'ZK Trust Attestation',
      description:
        'RISC Zero zero-knowledge proofs for privacy-preserving trust verification. VaultfireTrustAttestation contract.',
      tags: ['zk', 'trust', 'attestation', 'risc-zero', 'privacy'],
      examples: [
        'Get ZK trust proof for agent 0x...',
        'Verify a trust attestation',
        'Check ZK attestation count',
      ],
    },
    {
      id: 'belief-attestation',
      name: 'Belief Attestation',
      description:
        'Verify AI belief systems and value alignment — belief-weighted governance (not token-weighted). BeliefAttestationVerifier, ProductionBAV, and DilithiumAttestor.',
      tags: ['belief', 'attestation', 'dilithium', 'post-quantum', 'governance'],
      examples: [
        'Verify belief attestation for 0x...',
        'Check Dilithium post-quantum signature',
        'Get production attestation status',
      ],
    },
    {
      id: 'mission-enforcement',
      name: 'Mission Enforcement',
      description:
        'Check agent mission compliance. MissionEnforcement contract ensures agents follow their stated mission.',
      tags: ['mission', 'compliance', 'enforcement', 'ethics'],
      examples: [
        'Check mission compliance for agent 0x...',
        'Is this agent mission-aligned?',
      ],
    },
    {
      id: 'privacy-protection',
      name: 'Privacy & Anti-Surveillance',
      description:
        'AntiSurveillance and PrivacyGuarantees contracts — check surveillance protection status and cryptographic privacy guarantees.',
      tags: ['privacy', 'anti-surveillance', 'protection', 'guarantees'],
      examples: [
        'Check anti-surveillance status for 0x...',
        'Verify privacy guarantees on Base',
      ],
    },
    {
      id: 'flourishing-metrics',
      name: 'Flourishing Metrics Oracle',
      description:
        'Measures positive human outcomes — the entire protocol exists for human flourishing. FlourishingMetricsOracle contract.',
      tags: ['flourishing', 'metrics', 'oracle', 'human-outcomes'],
      examples: [
        'Get flourishing metrics on Base',
        'Check current flourishing index',
      ],
    },
    {
      id: 'governance',
      name: 'Multisig Governance',
      description:
        'Multi-signature governance for protocol changes. MultisigGovernance contract.',
      tags: ['governance', 'multisig', 'proposals', 'voting'],
      examples: [
        'Check governance proposal count',
        'View proposal #1 status',
      ],
    },
    {
      id: 'validation-registry',
      name: 'Validation Registry',
      description:
        'ERC8004ValidationRegistry — verify agent compliance with ethical standards and validation status.',
      tags: ['validation', 'compliance', 'registry', 'erc-8004'],
      examples: [
        'Check validation status for 0x...',
        'Is this agent validated?',
      ],
    },
    {
      id: 'erc8004-adapter',
      name: 'ERC-8004 Adapter',
      description:
        'VaultfireERC8004Adapter — adapter queries for ERC-8004 compatibility and integration.',
      tags: ['adapter', 'erc-8004', 'compatibility', 'integration'],
      examples: [
        'Query adapter status on Base',
        'Check ERC-8004 adapter config',
      ],
    },
    {
      id: 'cross-chain-bridge',
      name: 'Cross-Chain Trust Bridge',
      description:
        'VaultfireTeleporterBridge syncs agent trust data across all 4 chains via Avalanche Warp Messaging.',
      tags: ['bridge', 'cross-chain', 'teleporter', 'sync'],
      examples: [
        'Check bridge status on Avalanche',
        'Is agent 0x... recognized on Arbitrum?',
      ],
    },
    {
      id: 'agent-discovery',
      name: 'Agent Discovery & Routing',
      description:
        'Discover registered agents, filter by capabilities, route tasks to the best match.',
      tags: ['discovery', 'routing', 'matching', 'directory'],
      examples: [
        'Find all registered agents',
        'Route this task to the best agent on Base',
      ],
    },
    {
      id: 'messaging',
      name: 'XMTP Encrypted Messaging',
      description:
        'End-to-end encrypted agent-to-agent messaging via XMTP. Trust-gated — agents verify bond status before processing.',
      tags: ['messaging', 'xmtp', 'encrypted', 'communication'],
      examples: [
        'Send a message to agent 0x...',
        'Check message history',
      ],
    },
  ],

  // ─── Vaultfire Trust Extension ─────────────────────────────
  'x-vaultfire': {
    protocol: 'vaultfire',
    hubChain: 'base',
    supportedChains: ['base', 'avalanche', 'arbitrum', 'polygon'],
    totalContracts: 134,
    chainBreakdown: { base: 36, avalanche: 32, arbitrum: 33, polygon: 33 },
    identityStandard: 'ERC-8004',
    nameService: 'VNS (.vns) — agent-only, available on Base / Arbitrum / Polygon',
    trustScoring: {
      streetCred: { range: [0, 95], tiers: ['Newcomer', 'Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond'] },
      onChainRating: { range: [0, 10000], source: 'ERC8004ReputationRegistry' },
    },
    contracts: {
      base: {
        ERC8004IdentityRegistry: '0xa7BD20bf5De63df949cA5Be2F20835978eCba81A',
        AIPartnershipBonds: '0x01C479F0c039fEC40c0Cf1c5C921bab457d57441',
        AIAccountabilityBonds: '0x6750D28865434344e04e1D0a6044394b726C3dfE',
        ERC8004ReputationRegistry: '0x98afd1440B2238D73c1394720277a6d031fCbbD0',
        ERC8004ValidationRegistry: '0x8D3495772EAcAdB7dC09F1784eF06F2D109fb8a5',
        FlourishingMetricsOracle: '0xf7B2dC73Ec69528F171F4a0ded62da557866BaA5',
        VaultfireERC8004Adapter: '0x8bEFe7411AecddA6E1Aea8F031fedD293Ca7372E',
        MultisigGovernance: '0x34a19C7298aCA59e185F1ecfB352AC566bB4B4A9',
        ProductionBeliefAttestationVerifier: '0x2a46B5932e9559176241056A04a608B8fEbCc5A7',
        DilithiumAttestor: '0xef703bBe9b21960ede3e96abBB0Bbd0c525Fe050',
        VaultfireTeleporterBridge: '0x62edf0cBc8Fa3d98B6A07197DFE9cb1c128a7eC7',
        BeliefAttestationVerifier: '0x32211773C8266774A704aeD471f8eF073f34bA79',
        VaultfireNameService: '0xA9e6c2c0a731F1f56F6720Dfac2eB1440Ab9453a',
        MissionEnforcement: '0xBc4208A7A59af3B7E438d3308C3dc0d299d739a7',
        AntiSurveillance: '0xaaC44F1396f3F5b3C06048a1F819DC9b0f86D90c',
        PrivacyGuarantees: '0x2711AA5f1934Fe97825F02e51cB5Da58d1759625',
        VaultfireTrustAttestation: '0xc0f8704EF84Ca58Fa0AF4836669d358574FFE1f4',
        VaultfireTaskEscrow: '0x70098737Cb41827b7a86397B42c166020BCcC03b',
        VKPSessionKeyManager: '0x18622Fd3DF3269Ef3cf53cF374eB011A36DC4Be5',
        VKPDelegationRegistry: '0xd4d32b5c28040AFA2A6aB0ae9FF6DA68EAee4F82',
        VKPFactory: '0x174E29E6FAdD3096387030429Eb4677eA569e625',
        VaultfireReputationStaking: '0xd42BBfD3061A38D4B5540317A31D90212380069b',
        VaultfireTrustOracle: '0xF945aA87dB4E1d14aa7d0572501afa166374B776',
        VaultfireBondInsurancePool: '0xa074e372d5221b605E9762e41B86EbdBEBF1a978',
        VaultfireCapabilityCredentials: '0x4C7fddDdae8855283e98dA80BDf7aEa51A0b772B',
        VaultfireDisputeResolution: '0x3a681b6eF98c6d35643Ca631eE50EF35edd6BcBD',
      },
      avalanche: {
        ERC8004IdentityRegistry: '0x7448057C95Fb8a8B974a566cdcc9Cd042166A3f8',
        AIPartnershipBonds: '0xDC8447c66fE9D9c7D54607A98346A15324b7985D',
        AIAccountabilityBonds: '0x376831fB2457E34559891c32bEb61c442053C066',
        ERC8004ReputationRegistry: '0x5DB1B4b412b80d03819395794fCcF5A73BF30656',
        ERC8004ValidationRegistry: '0x44f1241F5F1A76c146d580142E54590a130410B4',
        FlourishingMetricsOracle: '0x1437c4081233A4f0B6907dDf5374Ed610cBD6B25',
        VaultfireERC8004Adapter: '0x69D3458aba750Fa85d4a25b3A23B398A3D9494fe',
        MultisigGovernance: '0x3ceA2B0853B76Ac75603C1fa2A29D96A4467Bb79',
        ProductionBeliefAttestationVerifier: '0xFa8ed66E27379942cB90BB5f612F0170a5dE4924',
        DilithiumAttestor: '0x9CF1fcba0c657e9FD807a9c8c028E0ef561b6B56',
        VaultfireTeleporterBridge: '0x1762e484A48558Ea5Cd056ac2CDf43FBbA52ba58',
        BeliefAttestationVerifier: '0x756bf61bF3948886a36D00ECB02CEDBdb3215c4C',
        MissionEnforcement: '0xA4F4EDd4ed280Bd784650c048190fBA16e0AFd11',
        AntiSurveillance: '0x7b9293B05Bd0fcb7458d06A364078761B8E8848e',
        PrivacyGuarantees: '0x1a7391DD19Dadab89757E58F4Cf988455263533e',
        VaultfireTrustAttestation: '0x5F7680a9a720c03812532A735D1165D9f97c0Cd1',
        VaultfireTaskEscrow: '0xa7BD20bf5De63df949cA5Be2F20835978eCba81A',
        VKPSessionKeyManager: '0xE02F5029fcDd6c51e957eb3895bd5805126A5Cdc',
        VKPDelegationRegistry: '0x3f385774dba7d067cda7E5190a659029BF8219dB',
        VKPFactory: '0x12f3e926122DB6A9A65740b90981c947EF18aC40',
        VaultfireReputationStaking: '0x32211773C8266774A704aeD471f8eF073f34bA79',
        VaultfireTrustOracle: '0x01C479F0c039fEC40c0Cf1c5C921bab457d57441',
        VaultfireBondInsurancePool: '0xf7B2dC73Ec69528F171F4a0ded62da557866BaA5',
        VaultfireCapabilityCredentials: '0x6750D28865434344e04e1D0a6044394b726C3dfE',
        VaultfireDisputeResolution: '0x98afd1440B2238D73c1394720277a6d031fCbbD0',
      },
      arbitrum: {
        ERC8004IdentityRegistry: '0x83dd216449B3F0574E39043ECFE275946fa492e9',
        AIPartnershipBonds: '0xdB54B8925664816187646174bdBb6Ac658A55a5F',
        AIAccountabilityBonds: '0xef3A944f4d7bb376699C83A29d7Cb42C90D9B6F0',
        ERC8004ReputationRegistry: '0x8B8Ba34F8AAB800F0Ba8391fb1388c6EFb911F92',
        ERC8004ValidationRegistry: '0xa5CEC47B48999EB398707838E3A18dd20A1ae272',
        FlourishingMetricsOracle: '0x54e00081978eE2C8d9Ada8e9975B0Bb543D06A55',
        VaultfireERC8004Adapter: '0xBBC0EFdEE23854e7cb7C4c0f56fF7670BB0530A4',
        MultisigGovernance: '0x94F54c849692Cc64C35468D0A87D2Ab9D7Cb6Fb2',
        ProductionBeliefAttestationVerifier: '0xf757f8650109cE7a89dd8f041DE69D861B64DD23',
        DilithiumAttestor: '0xA4F4EDd4ed280Bd784650c048190fBA16e0AFd11',
        VaultfireTeleporterBridge: '0x7b9293B05Bd0fcb7458d06A364078761B8E8848e',
        BeliefAttestationVerifier: '0xf92baef9523BC264144F80F9c31D5c5C017c6Da8',
        VaultfireNameService: '0x7448057C95Fb8a8B974a566cdcc9Cd042166A3f8',
        MissionEnforcement: '0x35978DB675576598F0781dA2133E94cdCf4858bC',
        AntiSurveillance: '0xD9bF6D92a1D9ee44a48c38481c046a819CBdf2ba',
        PrivacyGuarantees: '0xC574CF2a09B0B470933f0c6a3ef422e3fb25b4b4',
        VaultfireTrustAttestation: '0x1a7391DD19Dadab89757E58F4Cf988455263533e',
        VaultfireTaskEscrow: '0x5F7680a9a720c03812532A735D1165D9f97c0Cd1',
        VKPSessionKeyManager: '0x796d903923a0f4264E5B4dB46013cB186Fc610E2',
        VKPDelegationRegistry: '0xA505996f4A1291DD7a6981Ab825E35418b2711de',
        VKPFactory: '0x65adEd8CCAe58FD3fAd6a84BDA323C78d9eD4269',
        VaultfireReputationStaking: '0x9d4AbeAa8201e6f1649c296dd179Bbb3c401f96F',
        VaultfireTrustOracle: '0xFeF83A66fC1f3c8311070FDd502cd90deD0B3C33',
        VaultfireBondInsurancePool: '0xAca6fe18917a985F6741FB986461B976e2A0a5DB',
        VaultfireCapabilityCredentials: '0x472dF1dD6D8218D0BF748e910E32861dAb88EDA6',
        VaultfireDisputeResolution: '0x152a0446958f48EB3F1f5126FAF418D663359e95',
      },
      polygon: {
        ERC8004IdentityRegistry: '0xD9bF6D92a1D9ee44a48c38481c046a819CBdf2ba',
        AIPartnershipBonds: '0x83dd216449B3F0574E39043ECFE275946fa492e9',
        AIAccountabilityBonds: '0xdB54B8925664816187646174bdBb6Ac658A55a5F',
        ERC8004ReputationRegistry: '0x54e00081978eE2C8d9Ada8e9975B0Bb543D06A55',
        ERC8004ValidationRegistry: '0xBBC0EFdEE23854e7cb7C4c0f56fF7670BB0530A4',
        FlourishingMetricsOracle: '0xf92baef9523BC264144F80F9c31D5c5C017c6Da8',
        VaultfireERC8004Adapter: '0x94F54c849692Cc64C35468D0A87D2Ab9D7Cb6Fb2',
        MultisigGovernance: '0x5DB1B4b412b80d03819395794fCcF5A73BF30656',
        ProductionBeliefAttestationVerifier: '0xf757f8650109cE7a89dd8f041DE69D861B64DD23',
        DilithiumAttestor: '0xA4F4EDd4ed280Bd784650c048190fBA16e0AFd11',
        VaultfireTeleporterBridge: '0x7b9293B05Bd0fcb7458d06A364078761B8E8848e',
        BeliefAttestationVerifier: '0xC574CF2a09B0B470933f0c6a3ef422e3fb25b4b4',
        VaultfireNameService: '0x7448057C95Fb8a8B974a566cdcc9Cd042166A3f8',
        MissionEnforcement: '0x722E37A7D6f27896C688336AaaFb0dDA80D25E57',
        AntiSurveillance: '0xE2f75A4B14ffFc1f9C2b1ca22Fdd6877E5BD5045',
        PrivacyGuarantees: '0x35978DB675576598F0781dA2133E94cdCf4858bC',
        VaultfireTrustAttestation: '0x1a7391DD19Dadab89757E58F4Cf988455263533e',
        VaultfireTaskEscrow: '0x69D3458aba750Fa85d4a25b3A23B398A3D9494fe',
        VKPSessionKeyManager: '0x4A614DB779e38B47952DCCc2e88F0A6afb35c419',
        VKPDelegationRegistry: '0x064d7e8a3A24909ef83d537dBA10Dfcd3D44912C',
        VKPFactory: '0x1d7eDE881093748B0a6feBc47cA9D681C19d8333',
        VaultfireReputationStaking: '0x3ceA2B0853B76Ac75603C1fa2A29D96A4467Bb79',
        VaultfireTrustOracle: '0xFa8ed66E27379942cB90BB5f612F0170a5dE4924',
        VaultfireBondInsurancePool: '0x9CF1fcba0c657e9FD807a9c8c028E0ef561b6B56',
        VaultfireCapabilityCredentials: '0x1762e484A48558Ea5Cd056ac2CDf43FBbA52ba58',
        VaultfireDisputeResolution: '0x5F7680a9a720c03812532A735D1165D9f97c0Cd1',
      },
    },
    apiBase: 'https://theloopbreaker.com/api',
    mcp: { url: 'https://theloopbreaker.com/api/mcp', transport: 'http' },
    npm: '@vaultfire/a2a',
    motto: 'Break the loop. Trust the agent.',
    releaseStatus: {
      x402: 'disabled_pending_readiness_evidence',
      note: 'x402 payment routes, including x402-Email verification, are disabled until release-readiness evidence is independently reviewed.',
    },
  },
};

export async function GET() {
  return NextResponse.json(AGENT_CARD, {
    headers: {
      'Cache-Control': 'public, max-age=300',
      'Access-Control-Allow-Origin': '*',
    },
  });
}
