//! Tests for types module

use crate::dev::types::{DevConfig, DevEnvironment};

#[test]
fn test_dev_environment_from_str() {
    assert_eq!(DevEnvironment::parse_environment("dev"), DevEnvironment::Dev);
    assert_eq!(DevEnvironment::parse_environment("Development"), DevEnvironment::Dev);
    assert_eq!(DevEnvironment::parse_environment("staging"), DevEnvironment::Staging);
    assert_eq!(DevEnvironment::parse_environment("PROD"), DevEnvironment::Production);
    assert_eq!(
        DevEnvironment::parse_environment("custom"),
        DevEnvironment::Custom("custom".to_string())
    );
}

#[test]
fn test_dev_environment_as_str() {
    assert_eq!(DevEnvironment::Dev.as_str(), "dev");
    assert_eq!(DevEnvironment::Staging.as_str(), "staging");
    assert_eq!(DevEnvironment::Production.as_str(), "production");
    assert_eq!(DevEnvironment::Custom("test".to_string()).as_str(), "test");
}

#[test]
fn test_dev_environment_display_name() {
    assert_eq!(DevEnvironment::Dev.display_name(), "Development");
    assert_eq!(DevEnvironment::Staging.display_name(), "Staging");
    assert_eq!(DevEnvironment::Production.display_name(), "Production");
    assert_eq!(DevEnvironment::Custom("test".to_string()).display_name(), "test");
}

#[test]
fn test_dev_config_builder() {
    let config = DevConfig::new(DevEnvironment::Dev)
        .with_watch(true)
        .with_node("speaker")
        .with_node("listener")
        .with_no_build(false)
        .with_auto_start_services(true)
        .with_flush_redis(true)
        .with_env_var("TEST_VAR", "test_value");

    assert_eq!(config.environment, DevEnvironment::Dev);
    assert!(config.watch);
    assert!(!config.no_build);
    assert_eq!(config.nodes, vec!["speaker", "listener"]);
    assert!(config.auto_start_services);
    assert!(config.flush_redis);
    assert_eq!(config.env_vars.get("TEST_VAR"), Some(&"test_value".to_string()));
}

#[test]
fn test_dev_config_defaults() {
    let config = DevConfig::default();

    assert_eq!(config.environment, DevEnvironment::Dev);
    assert!(!config.watch);
    assert!(!config.no_build);
    assert!(config.nodes.is_empty());
    assert!(config.auto_start_services);
    assert!(config.flush_redis);
    assert!(config.env_vars.is_empty());
}
