from core.database.abc.db_model_dao_abc import DbModelDaoABC
from core.logger import DBLogger
from data.schemas.permission.role_user import RoleUser

logger = DBLogger(__name__)


class RoleUserDao(DbModelDaoABC[RoleUser]):

    def __init__(self):
        DbModelDaoABC.__init__(self, __name__, RoleUser, "permission.role_users")

        self.attribute(RoleUser.role_id, int)
        self.attribute(RoleUser.user_id, int)

    async def get_by_role_id(self, rid: int, with_deleted=False) -> list[RoleUser]:
        f = [{RoleUser.role_id: rid}]
        if not with_deleted:
            f.append({RoleUser.deleted: False})

        return await self.find_by(f)

    async def get_by_user_id(self, uid: int, with_deleted=False) -> list[RoleUser]:
        f = [{RoleUser.user_id: uid}]
        if not with_deleted:
            f.append({RoleUser.deleted: False})

        return await self.find_by(f)


roleUserDao = RoleUserDao()
