from __future__ import annotations

from typing import Any


class ACLVariableError(KeyError):
    def __init__(self, name: str, message: str | None = None) -> None:
        self.name = name
        self.code = "variable_error"
        super().__init__(message or f"undefined variable: {name}")


class ContextStore:
    def __init__(self) -> None:
        self._values: dict[str, Any] = {}

    def set(self, name: str, value: Any) -> None:
        self._values[name] = value

    def get(self, name: str) -> Any:
        if name not in self._values:
            raise ACLVariableError(name)
        return self._values[name]

    def has(self, name: str) -> bool:
        return name in self._values

    def snapshot(self) -> dict[str, Any]:
        return dict(self._values)

    def clear(self) -> None:
        self._values.clear()
