use std::path::Path;

fn workspace_root() -> std::path::PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .and_then(Path::parent)
        .expect("workspace root")
        .to_path_buf()
}

#[test]
fn cli_no_longer_houses_demo_implementation_modules() {
    let cli_src = workspace_root().join("crates/bucketwarden-cli/src");
    for module in [
        "bucket_demos.rs",
        "bucket_extras.rs",
        "core_demos.rs",
        "http_demos.rs",
        "lifecycle_demos.rs",
        "multipart_demos.rs",
        "object_demos.rs",
        "replication_demos.rs",
        "security_demos.rs",
        "bucket_extras",
        "http_demos",
    ] {
        assert!(
            !cli_src.join(module).exists(),
            "demo implementation should live in bucketwarden-demo: {module}"
        );
    }
}

#[test]
fn planned_boundary_crates_are_workspace_packages() {
    let root = workspace_root();
    for package in [
        "bucketwarden-demo",
        "bucketwarden-crypto",
        "bucketwarden-errors",
        "bucketwarden-http",
        "bucketwarden-storage",
        "bucketwarden-fs",
        "bucketwarden-buckets",
        "bucketwarden-objects",
        "bucketwarden-lifecycle",
        "bucketwarden-replication",
        "bucketwarden-xml",
        "bucketwarden-validators",
        "bucketwarden-ops",
        "bucketwarden-console-api",
        "bucketwarden-browser-ui",
    ] {
        assert!(
            root.join("crates")
                .join(package)
                .join("Cargo.toml")
                .exists(),
            "missing planned boundary crate: {package}"
        );
    }
}
