//! Shared test utilities for I/O module tests.
//!
//! Import with `use crate::io::test_helpers::{create_test_files, setup_project};`

use std::fs;
use std::path::PathBuf;
use tempfile::TempDir;

/// Create a minimal huskies project directory structure under `dir`.
///
/// Creates `.huskies/specs/tech/` and `script/`, then returns the root path.
/// Used by onboarding and wizard tests.
pub(crate) fn setup_project(dir: &TempDir) -> PathBuf {
    let root = dir.path().to_path_buf();
    let sk = root.join(".huskies");
    fs::create_dir_all(sk.join("specs").join("tech")).unwrap();
    fs::create_dir_all(root.join("script")).unwrap();
    root
}

/// Write a set of files into `dir` at the given relative paths.
///
/// Parent directories are created automatically.  Used by search tests.
pub(crate) fn create_test_files(dir: &TempDir, files: &[(&str, &str)]) {
    for (path, content) in files {
        let full = dir.path().join(path);
        if let Some(parent) = full.parent() {
            fs::create_dir_all(parent).unwrap();
        }
        fs::write(full, content).unwrap();
    }
}
