from .base import Worker, WorkerContext, WorkerResult
from .compressor import CompressionWorker


def build_default_workers() -> list[Worker]:
    """Auto-discover and instantiate all built-in workers."""
    import importlib
    import inspect
    from pathlib import Path

    workers: list[Worker] = []
    pkg_dir = Path(__file__).parent

    for py_file in sorted(pkg_dir.glob("*.py")):
        if py_file.name.startswith("_"):
            continue
        mod_name = f"navi.workers.{py_file.stem}"
        try:
            mod = importlib.import_module(mod_name)
        except Exception:
            continue
        for _name, obj in inspect.getmembers(mod):
            if (
                inspect.isclass(obj)
                and issubclass(obj, Worker)
                and obj is not Worker
                and not getattr(obj, "__abstractmethods__", None)
            ):
                try:
                    instance = obj()
                    workers.append(instance)
                except Exception:
                    pass

    return workers


__all__ = [
    "Worker",
    "WorkerContext",
    "WorkerResult",
    "CompressionWorker",
    "build_default_workers",
]
