use std::{path::PathBuf, sync::LazyLock};


/// The `target/` directory of your workspace.
///
/// Compile artifacts can be found in here.
pub fn target_dir() -> PathBuf {
    USER_WORKSPACE_DIR.join("target")
}

pub static USER_WORKSPACE_CARGO_TOML: LazyLock<PathBuf> = LazyLock::new(|| {
    let output = std::process::Command::new(env!("CARGO"))
        .arg("locate-project")
        .arg("--workspace")
        .arg("--message-format=plain")
        .output()
        .unwrap()
        .stdout;

    let output = std::str::from_utf8(&output).unwrap()
        .trim();

    PathBuf::from(output)
});

pub static USER_WORKSPACE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
    USER_WORKSPACE_CARGO_TOML
        .parent().unwrap()
        .to_path_buf()
});


/// Paths used by Cicero.
pub mod cicero {
    use std::path::PathBuf;

    /// The directory where Cicero places its artifacts.
    /// This is a sub-path of the `target/` folder.
    pub fn target() -> PathBuf {
        super::target_dir().join("cicero")
    }

    /// Directory used for internal logic of Cicero.
    pub fn internal() -> PathBuf {
        target().join(".internal")
    }
}
