import { type DomainError, type Encounter, isDomainError, undo, } from "@initiative/domain"; import type { EncounterStore, UndoRedoStore } from "./ports.js"; export function undoUseCase( encounterStore: EncounterStore, undoRedoStore: UndoRedoStore, ): Encounter | DomainError { const current = encounterStore.get(); const state = undoRedoStore.get(); const result = undo(state, current); if (isDomainError(result)) { return result; } encounterStore.save(result.encounter); undoRedoStore.save(result.state); return result.encounter; }