// Tests for mecha10_cli::services::topic_monitor

use mecha10_cli::services::topic_monitor::*;

#[test]
fn test_topic_monitor_service_creation() {
    let service = TopicMonitorService::new("redis://localhost:6379");
    assert_eq!(service.redis_url, "redis://localhost:6379");
}

#[test]
fn test_parse_message_payload_with_envelope() {
    let service = TopicMonitorService::new("redis://localhost:6379");
    let data = r#"{"payload": {"sensor": "camera", "value": 42}}"#;

    let payload = service.parse_message_payload(data).unwrap();
    assert_eq!(payload["sensor"], "camera");
    assert_eq!(payload["value"], 42);
}

#[test]
fn test_parse_message_payload_without_envelope() {
    let service = TopicMonitorService::new("redis://localhost:6379");
    let data = r#"{"sensor": "camera", "value": 42}"#;

    let payload = service.parse_message_payload(data).unwrap();
    assert_eq!(payload["sensor"], "camera");
    assert_eq!(payload["value"], 42);
}

#[test]
fn test_parse_message_payload_plain_text() {
    let service = TopicMonitorService::new("redis://localhost:6379");
    let data = "plain text message";

    let payload = service.parse_message_payload(data).unwrap();
    assert_eq!(payload, serde_json::Value::String("plain text message".to_string()));
}
