"""
Exemplo de uso do Audit Ledger
"""
from atomic_agents.core import AuditLedger

def main():
    ledger = AuditLedger()
    
    print("=== Demonstração do Audit Ledger ===\n")
    
    # Simular uma sequência de eventos
    events = [
        {"event": "llm_start", "prompt": "Summarize this text", "model": "gpt-4"},
        {"event": "llm_end", "tokens_used": 150, "cost": 0.03},
        {"event": "tool_call", "tool": "search", "query": "Python best practices"},
        {"event": "llm_start", "prompt": "Analyze the results", "model": "gpt-4"},
        {"event": "llm_end", "tokens_used": 200, "cost": 0.04},
    ]
    
    print("Registrando eventos...\n")
    for event in events:
        entry = ledger.record(event)
        print(f"Evento: {event['event']}")
        print(f"Hash: {entry['hash'][:16]}...")
        print(f"Hash anterior: {entry['previous_hash'][:16]}...")
        print()
    
    # Verificar integridade da cadeia
    print("=== Verificação de Integridade ===\n")
    for i, entry in enumerate(ledger.entries):
        print(f"Entrada {i+1}:")
        print(f"  Evento: {entry['data']['event']}")
        print(f"  Hash: {entry['hash'][:16]}...")
        if i > 0:
            prev_hash = ledger.entries[i-1]['hash']
            is_valid = entry['previous_hash'] == prev_hash
            print(f"  Hash anterior válido: {'✅' if is_valid else '❌'}")
        print()

if __name__ == "__main__":
    main()


