"""Minimal principal context helpers."""

from __future__ import annotations

from contextvars import ContextVar

from .authz import Principal

_principal: ContextVar[Principal] = ContextVar("principal", default=Principal.guest())


def set_principal(value: Principal) -> None:
    """Set principal for the current context."""

    _principal.set(value)


def principal() -> Principal:
    """Return principal for the current context."""

    return _principal.get()


__all__ = ["principal", "set_principal"]

