"""registry.discovery — A2A agent discovery."""
from __future__ import annotations
import json
from typing import Dict
from agentpaas.db.session import get_db


def get_agent_card(agent_id: str, base_url: str = "") -> Dict:
    """Generate A2A Agent Card for external discovery."""
    db = get_db()
    agent = db.fetchone("SELECT * FROM agents WHERE id=? AND status='active'", (agent_id,))
    if not agent:
        return {}
    return {
        "name": agent["name"],
        "description": agent.get("description", ""),
        "url": f"{base_url}/api/v1/agents/{agent_id}",
        "capabilities": json.loads(agent.get("tags", "[]")),
        "protocol": "a2a/1.0",
        "authentication": {"type": "bearer"},
    }
