use std::path::PathBuf;

pub fn maybe_data_dir() -> Option<PathBuf> {
    const LOCAL_DEFAULT: &str = "/mnt/Win/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack/ffxiv";

    let dir = std::env::var("SQPACK_TEST_DATA_DIR")
        .ok()
        .or_else(|| {
            std::path::Path::new(LOCAL_DEFAULT)
                .is_dir()
                .then(|| LOCAL_DEFAULT.to_string())
        })
        .map(PathBuf::from)?;

    if dir.is_dir() { Some(dir) } else { None }
}

#[allow(dead_code)]
pub fn install_root_from_data_dir(data_dir: &std::path::Path) -> Option<PathBuf> {
    let root = data_dir.parent()?.parent()?;
    Some(root.to_path_buf())
}
