//! Smoke tests for JobQueueEscalation: raise / resolve / list.

use klieo_bus_memory::MemoryBus;
use klieo_core::JobQueue;
use klieo_ops::escalation::{
    Escalation, EscalationFilter, EscalationState, EscalationTicket, JobQueueEscalation,
    Resolution, ResolutionOutcome, Severity,
};
use std::sync::Arc;

#[tokio::test]
async fn raise_then_list_returns_ticket() {
    let bus = MemoryBus::new();
    let jobs: Arc<dyn JobQueue> = bus.jobs.clone();
    let esc = JobQueueEscalation::new(jobs);
    let id = esc
        .raise(EscalationTicket::new(Severity::High, "test", None, None))
        .await
        .expect("raise");
    let listed = esc.list(EscalationFilter::default()).await;
    assert_eq!(listed.len(), 1);
    assert_eq!(listed[0].severity, Severity::High);
    assert!(!id.0.is_empty());
}

#[tokio::test]
async fn resolve_transitions_state() {
    let bus = MemoryBus::new();
    let esc = JobQueueEscalation::new(bus.jobs.clone());
    let id = esc
        .raise(EscalationTicket::new(Severity::Medium, "test", None, None))
        .await
        .expect("raise");
    esc.resolve(
        id,
        Resolution::new(ResolutionOutcome::Approved, None, vec![], vec![]),
    )
    .await
    .expect("resolve");

    let mut filter = EscalationFilter::default();
    filter.states = Some(vec![EscalationState::Raised]);
    let active = esc.list(filter).await;
    assert_eq!(active.len(), 0, "Raised state must be empty after resolve");
}
