from pathlib import Path
import yaml

# Package data directory (installed via pip/uvx)
_PACKAGE_DATA = Path(__file__).parent.parent / "data"
# Development config directory (repo root/config)
_DEV_CONFIG = Path(__file__).parent.parent.parent.parent / "config"


def _load_yaml(filename: str) -> dict:
    for base in (_PACKAGE_DATA, _DEV_CONFIG):
        filepath = base / filename
        if filepath.exists():
            with open(filepath, encoding="utf-8") as f:
                return yaml.safe_load(f)
    raise FileNotFoundError(
        f"Config file not found: {filename} "
        f"(searched {_PACKAGE_DATA} and {_DEV_CONFIG})"
    )


def load_rules() -> dict:
    return _load_yaml("rules.yaml")


def load_patterns() -> dict:
    return _load_yaml("patterns.yaml")


def load_config() -> dict:
    return _load_yaml("config.yaml")
