//! CLI command tests
#![allow(clippy::unwrap_used)] // Reason: test/bench code, panics are acceptable

#[cfg(test)]
mod command_tests {
    use std::str::FromStr;

    use crate::cli::OutputFormat;

    #[test]
    fn test_output_format_parsing() {
        assert_eq!(OutputFormat::from_str("text").unwrap(), OutputFormat::Text);
        assert_eq!(OutputFormat::from_str("json").unwrap(), OutputFormat::Json);
        assert_eq!(OutputFormat::from_str("TEXT").unwrap(), OutputFormat::Text);
    }

    #[test]
    fn test_output_format_invalid() {
        assert!(
            OutputFormat::from_str("invalid").is_err(),
            "\"invalid\" format must return error"
        );
        assert!(OutputFormat::from_str("yaml").is_err(), "\"yaml\" format must return error");
    }

    #[test]
    fn test_output_format_display() {
        assert_eq!(OutputFormat::Text.to_string(), "text");
        assert_eq!(OutputFormat::Json.to_string(), "json");
    }

    #[tokio::test]
    async fn test_status_command_text_format() {
        let result = crate::cli::commands::status::execute(OutputFormat::Text, None, false).await;
        result.expect("CLI command should succeed");
    }

    #[tokio::test]
    async fn test_status_command_json_format() {
        let result = crate::cli::commands::status::execute(OutputFormat::Json, None, false).await;
        result.expect("CLI command should succeed");
    }

    #[tokio::test]
    async fn test_debug_event_command() {
        let result =
            crate::cli::commands::debug_event::execute(OutputFormat::Text, None, None, None, None)
                .await;
        result.expect("CLI command should succeed");
    }

    #[tokio::test]
    async fn test_debug_event_with_filters() {
        let result = crate::cli::commands::debug_event::execute(
            OutputFormat::Json,
            Some("evt-123".to_string()),
            Some(10),
            Some("Order".to_string()),
            Some("created".to_string()),
        )
        .await;
        result.expect("CLI command should succeed");
    }

    #[tokio::test]
    async fn test_validate_config_command() {
        let result =
            crate::cli::commands::validate_config::execute(OutputFormat::Text, None, false).await;
        result.expect("CLI command should succeed");
    }

    #[tokio::test]
    async fn test_validate_config_detailed() {
        let result =
            crate::cli::commands::validate_config::execute(OutputFormat::Json, None, true).await;
        result.expect("CLI command should succeed");
    }

    #[cfg(feature = "metrics")]
    #[tokio::test]
    async fn test_metrics_command() {
        let result = crate::cli::commands::metrics::execute(OutputFormat::Text, None, false).await;
        result.expect("CLI command should succeed");
    }

    #[cfg(feature = "metrics")]
    #[tokio::test]
    async fn test_metrics_json_format() {
        let result = crate::cli::commands::metrics::execute(OutputFormat::Json, None, false).await;
        result.expect("CLI command should succeed");
    }
}
