#!/usr/bin/env python3
import logging
import os
from pathlib import Path

logger = logging.getLogger()

WARNING_USAGE = """
You're not able to run the benchmark because the {submodule_name} dependency is not properly installed.

To fix this, please run one of these commands from the root of the repository:

```
git submodule update --init --recursive {submodule_name}
```

or for fetching all submodules:

```
git submodule update --init --recursive
```

After installing {submodule_name}, update your dependencies with:

```
uv sync --extra {submodule_name}
```

or for all submodules:

```
uv sync --extra submodules
```
"""


def check_dependency(submodule_name: str):
    osworld_path = Path(f"{os.path.dirname(__file__)}/../../{submodule_name}")

    # Check if osworld directory exists
    if not osworld_path.exists():
        logger.warning(WARNING_USAGE.format(submodule_name=submodule_name))
        return False

    # Check if directory is empty
    if not any(osworld_path.iterdir()):
        logger.warning(WARNING_USAGE.format(submodule_name=submodule_name))
        return False

    # Check for essential file
    missing_files = True if not (osworld_path / "pyproject.toml").exists() else False

    if missing_files:
        logger.warning(WARNING_USAGE.format(submodule_name=submodule_name))
        return False

    return True
