"""Settings service backed by repositories."""

from __future__ import annotations

from bot.domain.settings import ChatSettings
from bot.infra.db.repositories import lock_repository, settings_repository
from bot.services.cache import locks_cache, settings_cache


class SettingsService:
    async def get_settings(self, chat_id: int) -> ChatSettings:
        if chat_id not in settings_cache:
            settings_cache[chat_id] = await settings_repository.get_all(chat_id)

        return settings_cache[chat_id]

    async def get_locks(self, chat_id: int) -> set[str]:
        if chat_id not in locks_cache:
            locks_cache[chat_id] = await lock_repository.get_chat_locks(chat_id)

        return locks_cache[chat_id]


settings_service = SettingsService()
