*** Settings ***
Documentation    Smoke tests for EventBus infrastructure (EventType, DomainEvent,
...              ReactiveEventBus, LoggingEventBus, service emission, DI container)
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

*** Variables ***
${HELPER}    ${CURDIR}/helper_event_bus.py

*** Test Cases ***
EventType Values Are Present
    [Documentation]    Verify all required EventType string values exist
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    event_type_values
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    event-type-values-ok

DomainEvent Creation With Defaults
    [Documentation]    Verify DomainEvent constructs and applies default fields
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    domain_event_creation
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    domain-event-creation-ok

Protocol Conformance
    [Documentation]    Verify both bus implementations satisfy EventBus protocol
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    protocol_conformance
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    protocol-conformance-ok

ReactiveEventBus Emit And Subscribe
    [Documentation]    Verify ReactiveEventBus dispatches events to handlers
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    reactive_emit_subscribe
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    reactive-emit-subscribe-ok

LoggingEventBus Emit And Subscribe
    [Documentation]    Verify LoggingEventBus dispatches events to handlers
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    logging_emit_subscribe
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    logging-emit-subscribe-ok

ReactiveEventBus Type Filtering
    [Documentation]    Verify ReactiveEventBus only dispatches to matching event type
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    reactive_type_filtering
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    reactive-type-filtering-ok

DecisionService Emits DECISION_CREATED
    [Documentation]    Verify DecisionService emits event via injected bus
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    decision_service_emits_event
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-service-emits-event-ok

PlanLifecycleService Emits PLAN_CREATED
    [Documentation]    Verify PlanLifecycleService emits event via injected bus
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan_lifecycle_emits_event
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-lifecycle-emits-event-ok

Container EventBus Is Singleton
    [Documentation]    Verify DI container provides same ReactiveEventBus instance
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    container_event_bus_singleton
    ...    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    container-event-bus-singleton-ok
