/**
 * Example: Enrich an A2A Agent Card with Vaultfire trust data.
 *
 * This example shows how to take a standard Google A2A Agent Card and
 * add on-chain trust data from the Vaultfire Protocol.
 */

import { enrichAgentCard } from '@vaultfire/a2a';
import type { AgentCard } from '@vaultfire/a2a';

// 1. Define your standard A2A Agent Card
const myAgentCard: AgentCard = {
  name: 'DataAnalysis Agent',
  description: 'Analyzes structured data and returns insights',
  url: 'https://my-agent.example.com',
  provider: {
    organization: 'Acme AI Labs',
    url: 'https://acmelabs.ai',
  },
  version: '2.0.0',
  documentationUrl: 'https://docs.acmelabs.ai/data-agent',
  capabilities: {
    streaming: true,
    pushNotifications: false,
    stateTransitionHistory: true,
  },
  defaultInputModes: ['text/plain', 'application/json'],
  defaultOutputModes: ['application/json', 'text/plain'],
  skills: [
    {
      id: 'csv-analysis',
      name: 'CSV Analysis',
      description: 'Reads CSV files and returns statistical summaries',
      tags: ['data', 'analytics', 'csv'],
      examples: [
        'Analyze this sales CSV and give me Q4 trends',
        'Find outliers in this dataset',
      ],
      inputModes: ['text/csv', 'application/json'],
      outputModes: ['application/json', 'text/plain'],
    },
    {
      id: 'chart-generator',
      name: 'Chart Generator',
      description: 'Generates charts from data',
      tags: ['visualization', 'charts'],
      outputModes: ['image/png', 'image/svg+xml'],
    },
  ],
};

// 2. Enrich with Vaultfire trust data
async function main() {
  console.log('Enriching Agent Card with Vaultfire trust data...\n');

  const enriched = await enrichAgentCard({
    agentCard: myAgentCard,
    chain: 'base',
    agentAddress: '0xfA15Ee28939B222B0448261A22156070f0A7813C',
  });

  console.log('Enriched Agent Card:');
  console.log(JSON.stringify(enriched, null, 2));

  // The x-vaultfire extension is now part of the card
  const trust = enriched['x-vaultfire'];
  console.log('\n--- Vaultfire Trust Summary ---');
  console.log(`Chain: ${trust.chain}`);
  console.log(`Address: ${trust.address}`);
  console.log(`Street Cred: ${trust.streetCred.score} / ${trust.streetCred.maxPossible} (${trust.streetCred.tier})`);
  console.log(`Active Bonds: ${trust.bonds.active} / ${trust.bonds.total}`);
  console.log(`Reputation: ${trust.reputation.averageRating.toFixed(1)} / 5.0 (${trust.reputation.totalFeedbacks} feedbacks)`);
  console.log(`Agent Status: ${trust.identity.active ? 'Active' : 'Inactive'} (${trust.identity.agentType})`);
  console.log(`Verified At: ${trust.verifiedAt}`);

  // 3. Serve it at /.well-known/agent.json
  console.log('\nTo serve this as your /.well-known/agent.json, use the Express middleware:');
  console.log(`
import express from 'express';
import { vaultfireAgentCardMiddleware } from '@vaultfire/a2a';

const app = express();

app.get('/.well-known/agent.json', vaultfireAgentCardMiddleware({
  agentCard: myAgentCard,
  chain: 'base',
  agentAddress: '0xfA15Ee28939B222B0448261A22156070f0A7813C',
  cacheTtl: 5 * 60 * 1000, // 5 minutes
}));

app.listen(3000, () => console.log('Agent serving on :3000'));
  `);
}

main().catch(console.error);
