from abc import ABCMeta, abstractmethod


class CacheRepository(metaclass=ABCMeta):
    @abstractmethod
    async def get(self, key: str) -> str | None:
        pass

    @abstractmethod
    async def set(self, key: str, data: str, _exp_min: int | None = None):
        pass

    @abstractmethod
    async def delete(self, key: str):
        pass


# TODO: сделать через общий кеш, например, redis. Работу с редис вынести в infra
class LocalCacheRepository(CacheRepository):
    _data: dict[str, str]

    def __init__(self) -> None:
        self._data = {}

    async def get(self, key: str) -> str | None:
        return self._data.get(key)

    async def set(self, key: str, data: str, _exp_min: int | None = None):
        self._data[key] = data

    async def delete(self, key: str):
        del self._data[key]
