from core.database.abc.db_model_dao_abc import DbModelDaoABC
from core.logger import DBLogger
from data.schemas.administration.user import User
from data.schemas.public.user_setting import UserSetting

logger = DBLogger(__name__)


class UserSettingDao(DbModelDaoABC[UserSetting]):

    def __init__(self):
        DbModelDaoABC.__init__(self, __name__, UserSetting, "public.user_settings")

        self.attribute(UserSetting.user_id, int)
        self.attribute(UserSetting.key, str)
        self.attribute(UserSetting.value, str)

    async def find_by_key(self, user: User, key: str) -> UserSetting:
        return await self.find_single_by(
            [{UserSetting.user_id: user.id}, {UserSetting.key: key}]
        )


userSettingDao = UserSettingDao()
