//! Architecture enforcement test for the `usecase` layer.
//!
//! The usecase layer must only depend on:
//!   - `astmap_core` (domain core: traits, models, scanner, diff, export)
//!   - Standard library (`std`)
//!   - Error handling crates (`anyhow`, `thiserror`)
//!   - `super` / sibling usecase modules
//!
//! Forbidden in production code (non-test):
//!   - `crate::infra` — infrastructure implementations
//!   - `astmap_languages` — language-specific parsers

#[path = "../../../tests/arch.rs"]
mod arch;

use std::path::Path;

const FORBIDDEN_PATTERNS: &[(&str, &str)] = &[
    ("crate::infra", "usecase must not depend on the infra layer"),
    (
        "astmap_languages",
        "usecase must not depend on astmap_languages",
    ),
];

#[test]
fn usecase_depends_only_on_core() {
    let src_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");

    let violations = arch::find_violations(&src_dir, "usecase", |line| {
        for &(pattern, reason) in FORBIDDEN_PATTERNS {
            if line.contains(pattern) {
                return Some(reason.to_string());
            }
        }
        None
    });

    assert!(
        violations.is_empty(),
        "ARCHITECTURE VIOLATION: usecase layer has forbidden dependencies:\n{}",
        violations.join("\n"),
    );
}
