from api_graphql.abc.db_model_query_abc import DbModelQueryABC
from data.schemas.permission.role_dao import roleDao
from data.schemas.permission.role_permission_dao import rolePermissionDao
from data.schemas.permission.role_user_dao import roleUserDao


class RoleQuery(DbModelQueryABC):
    def __init__(self):
        DbModelQueryABC.__init__(self, "Role", roleDao, with_history=True)

        self.set_field("name", lambda x, *_: x.name)
        self.set_field("description", lambda x, *_: x.description)
        self.set_field("permissions", lambda x, *_: x.permissions)
        self.set_field("users", lambda x, *_: x.users)

        self.set_history_reference_dao(rolePermissionDao, "roleid")
        self.set_history_reference_dao(roleUserDao, "roleid")
