from typing import Union
from pathlib import Path


def find_mo(search_paths=None) -> Union[Path, None]:
    """
    Args:
        search_paths: paths where ModelOptimizer may be found. If None only default paths is used.
    Returns:
        path to the ModelOptimizer or None if it wasn't found.
    """

    default_mo_path = ('intel', 'openvino', 'deployment_tools', 'model_optimizer')
    default_paths = [Path.home().joinpath(*default_mo_path), Path('/opt').joinpath(*default_mo_path)]

    executable = 'mo.py'
    for path in search_paths or default_paths:
        path = Path(path)
        if not path.is_dir():
            continue

        mo = path / executable
        if not mo.is_file():
            continue

        return mo

    return None