from core.logger import DBLogger

logger = DBLogger(__name__)

from core.database.abc.db_model_dao_abc import DbModelDaoABC
from data.schemas.permission.role import Role


class RoleDao(DbModelDaoABC[Role]):
    def __init__(self):
        DbModelDaoABC.__init__(self, __name__, Role, "permission.roles")
        self.attribute(Role.name, str)
        self.attribute(Role.description, str)

    async def get_by_name(self, name: str) -> Role:
        result = await self._db.select_map(
            f"SELECT * FROM {self._table_name} WHERE Name = '{name}'"
        )
        return self.to_object(result[0])


roleDao = RoleDao()
