"""Structural resource-registration contract for allocation-safe factories."""

from __future__ import annotations

from collections.abc import Callable
from typing import ParamSpec, Protocol, TypeVar

_P = ParamSpec("_P")
_T = TypeVar("_T")


class ResourceRegistrarProtocol(Protocol):
    def callback(
        self, close: Callable[_P, None], *args: _P.args, **kwargs: _P.kwargs
    ) -> None: ...

    def adopt(
        self, factory: Callable[[], _T], close: Callable[[_T], None]
    ) -> _T: ...

    def open_fd(self, opener: Callable[[], int]) -> int: ...

    def close_fd(self, descriptor: int) -> None: ...
