"""AppAdapter registry — route by os_family (DSL Phase 3c)."""

from __future__ import annotations

from typing import Any, Protocol

from .adapter_types import FocusResult, InstalledAppEntry, LaunchResult, TypeResult


class AppAdapter(Protocol):
    os_family: str

    def launch(self, app_id: str, entry: InstalledAppEntry, *, new_window: bool = True) -> LaunchResult: ...
    def focus(self, app_id: str, entry: InstalledAppEntry | None, *, window_hint: str = "") -> FocusResult: ...
    def type_text(self, app_id: str, text: str, *, submit: bool = False) -> TypeResult: ...
    def is_running(self, app_id: str, entry: InstalledAppEntry | None) -> bool: ...


def get_app_adapter(os_family: str) -> AppAdapter | None:
    family = str(os_family or "linux").lower()
    if family == "darwin":
        family = "macos"
    if family == "linux":
        from .linux.app_adapter import LinuxAppAdapter

        return LinuxAppAdapter()
    if family == "windows":
        from .windows.app_adapter import WindowsAppAdapter

        return WindowsAppAdapter()
    if family == "macos":
        from .macos.app_adapter import MacOSAppAdapter

        return MacOSAppAdapter()
    return None


def launch_candidates_from_installed_entry(entry: InstalledAppEntry) -> tuple[tuple[str, ...], ...]:
    from .linux.app_adapter import launch_candidates_from_installed_entry as _linux_candidates

    return _linux_candidates(entry)
