from api_graphql.abc.db_history_model_query_abc import DbHistoryModelQueryABC
from data.schemas.administration.user_dao import userDao
from data.schemas.permission.permission_dao import permissionDao
from data.schemas.permission.role_permission_dao import rolePermissionDao
from data.schemas.permission.role_user_dao import roleUserDao


class RoleHistoryQuery(DbHistoryModelQueryABC):
    def __init__(self):
        DbHistoryModelQueryABC.__init__(self, "Role")

        self.set_field("name", lambda x, *_: x.name)
        self.set_field("description", lambda x, *_: x.description)
        self.set_field(
            "permissions",
            lambda x, *_: self._resolve_foreign_history(
                x.updated,
                x.id,
                rolePermissionDao,
                permissionDao,
                lambda y: y.permission_id,
                obj_key="roleid",
            ),
        )
