from dataclasses import dataclass

from unmake import HistoryManager, OperationRegistry, SQLiteStorage


@dataclass
class PrintUndo:
    payload: dict[str, str]

    def undo(self) -> None:
        print(f"Undo marker: {self.payload['message']}")


manager = HistoryManager(SQLiteStorage("example.db"))
registry = OperationRegistry()
registry.register("custom.print", lambda payload: PrintUndo(payload))

with manager.start_session(script="custom_operations.py") as session:
    session.record_operation("custom.print", {"message": "reverse me"})

manager.undo_session(manager.list_sessions(limit=1)[0].session_id, registry)
