from typing import Protocol, TypeVar, Any, Optional

from bussdcc.context import ContextProtocol

ConfigT = TypeVar("ConfigT", covariant=True)


class DeviceProtocol(Protocol[ConfigT]):
    kind: str
    id: str
    ctx: Optional[ContextProtocol]

    @property
    def online(self) -> bool: ...

    def attach(self, ctx: ContextProtocol) -> None: ...
    def detach(self) -> None: ...
    def connect(self) -> None: ...
    def disconnect(self) -> None: ...


class DeviceManagerProtocol(Protocol):
    def attach(self, device: DeviceProtocol[Any]) -> None: ...
    def detach(self, id: str) -> None: ...
    def list(self, *, kind: Optional[str] = None) -> list[DeviceProtocol[Any]]: ...
    def get(self, id: str) -> Optional[DeviceProtocol[Any]]: ...
    def boot(self) -> None: ...
    def shutdown(self) -> None: ...
