import shutil
from pathlib import Path
from typing import Union

from clarabot_nano.utility.dirs import Directories


def dev_cache_dir():
    ds = Directories.instance()
    cache_dir = ds.get_user_app_data_dir("devtest", "cache")
    cache_dir.mkdir(parents=True, exist_ok=True)
    return cache_dir


def dev_build_dir():
    ds = Directories.instance()
    cache_dir = ds.get_user_app_data_dir("devtest", "build")
    cache_dir.mkdir(parents=True, exist_ok=True)
    return cache_dir


def get_first_file_found(*args: Union[str, Path]) -> str:
    for file in args:
        if isinstance(file, str):
            file = shutil.which(file)
            if file:
                return file
        elif file.is_file():
            return str(file)
        else:
            assert False, f"unsupported type {file}"
    assert False, f"not found any of {args}"
