from dataclasses import dataclass
from typing import Protocol


@dataclass(frozen=True, slots=True)
class StoredMaterial:
    content: bytes


class MaterialStorage(Protocol):
    def save(self, recognition_id: str, content: bytes) -> None: ...

    def load(self, recognition_id: str) -> StoredMaterial | None: ...

    def exists(self, recognition_id: str) -> bool: ...

    def delete(self, recognition_id: str) -> None: ...


class InMemoryMaterialStorage:
    def __init__(self) -> None:
        self._items: dict[str, bytes] = {}

    def save(self, recognition_id: str, content: bytes) -> None:
        self._items[recognition_id] = bytes(content)

    def load(self, recognition_id: str) -> StoredMaterial | None:
        content = self._items.get(recognition_id)
        return StoredMaterial(content) if content is not None else None

    def exists(self, recognition_id: str) -> bool:
        return recognition_id in self._items

    def delete(self, recognition_id: str) -> None:
        self._items.pop(recognition_id, None)
