from dataclasses import dataclass, field
from typing import List, Dict, Any


@dataclass
class TraceStep:
    agent: str
    role: str        # "input" or "output"
    content: str
    timestamp: str = ""

    def __post_init__(self):
        if not self.timestamp:
            from datetime import datetime
            self.timestamp = datetime.utcnow().isoformat()


@dataclass
class BridgeResult:
    final: str                          # Final answer from last agent
    trace: List[TraceStep] = field(default_factory=list)   # Full conversation log
    agents_used: List[str] = field(default_factory=list)   # Which agents ran

    def summary(self) -> str:
        lines = [f"=== Synapse Bridge Result ==="]
        lines.append(f"Agents used: {' → '.join(self.agents_used)}")
        lines.append("")
        for step in self.trace:
            lines.append(f"[{step.agent}] {step.role.upper()}")
            lines.append(f"  {step.content[:200]}{'...' if len(step.content) > 200 else ''}")
            lines.append("")
        lines.append(f"FINAL ANSWER:\n{self.final}")
        return "\n".join(lines)
