// Tests for mecha10_cli::services::component_catalog

use mecha10_cli::services::component_catalog::*;

#[test]
fn test_new_service() {
    let service = ComponentCatalogService::new();
    let all = service.get_all();
    assert!(!all.is_empty(), "Catalog should have components");
}

#[test]
fn test_get_by_type() {
    let service = ComponentCatalogService::new();

    let drivers = service.get_drivers();
    let packages = service.get_packages();
    let behaviors = service.get_behaviors();
    let stacks = service.get_stacks();

    // Should have at least some components
    assert!(!drivers.is_empty() || !packages.is_empty() || !behaviors.is_empty() || !stacks.is_empty());
}

#[test]
fn test_search() {
    let service = ComponentCatalogService::new();

    // Search should work case-insensitively
    let results = service.search("camera");
    assert!(!results.is_empty(), "Should find camera components");
}

#[test]
fn test_get_counts() {
    let service = ComponentCatalogService::new();
    let (drivers, packages, behaviors, stacks) = service.get_counts();

    // Total should be > 0
    assert!(drivers + packages + behaviors + stacks > 0);
}

#[test]
fn test_list_categories() {
    let service = ComponentCatalogService::new();
    let categories = service.list_categories();

    // Should be sorted and unique
    for i in 0..categories.len().saturating_sub(1) {
        assert!(categories[i] <= categories[i + 1]);
    }
}

#[test]
fn test_exists() {
    let service = ComponentCatalogService::new();

    // Should have at least one component
    let all = service.get_all();
    if let Some(component) = all.first() {
        assert!(service.exists(&component.id));
    }

    assert!(!service.exists("nonexistent-component-xyz"));
}
