@startuml Hook Vetoing Flow

title Hook Vetoing Flow - beforeAddQuad Events

participant "Test" as Test
participant "ObservableStore" as Store
participant "EventBus" as EventBus
participant "GitHook" as GitHook
participant "KnowledgeHook" as KH

== Vetoing Scenario ==
Test -> Store: addQuad(subject, predicate, object)
Store -> EventBus: emit('beforeAddQuad', payload)

EventBus -> EventBus: get beforeHooks
EventBus -> GitHook: call beforeAddQuad handler
GitHook -> GitHook: evaluate predicates
GitHook -> GitHook: return false (veto)
GitHook -> EventBus: return false

EventBus -> EventBus: operation vetoed
EventBus -> Store: return false
Store -> Store: skip adding quad to N3.Store
Note over Store: Quad NOT added

Store -> EventBus: emit('afterAddQuad', payload)
Note over EventBus: This should NOT happen
Note over EventBus: No afterAddQuad event emitted
Note over KH: Knowledge hook never called

== Non-Vetoing Scenario ==
Test -> Store: addQuad(subject, predicate, object)
Store -> EventBus: emit('beforeAddQuad', payload)

EventBus -> EventBus: get beforeHooks
EventBus -> GitHook: call beforeAddQuad handler
GitHook -> GitHook: evaluate predicates
GitHook -> GitHook: return true (allow)
GitHook -> EventBus: return true

EventBus -> EventBus: operation allowed
EventBus -> Store: return true
Store -> Store: actually add quad to N3.Store
Store -> EventBus: emit('afterAddQuad', payload)

EventBus -> GitHook: call afterAddQuad handler
GitHook -> Test: push to lifecycleEvents

EventBus -> KH: call afterAddQuad handler
KH -> Test: callback(result, payload)
Test -> Test: push to knowledgeEvents

@enduml
