from api_graphql.abc.db_history_model_query_abc import DbHistoryModelQueryABC
from data.schemas.permission.api_key_permission_dao import apiKeyPermissionDao
from data.schemas.permission.permission_dao import permissionDao


class ApiKeyHistoryQuery(DbHistoryModelQueryABC):
    def __init__(self):
        DbHistoryModelQueryABC.__init__(self, "ApiKey")

        self.set_field("identifier", lambda x, *_: x.identifier)
        self.set_field("key", lambda x, *_: x.key)
        self.set_field(
            "permissions",
            lambda x, *_: self._resolve_foreign_history(
                x.updated,
                x.id,
                apiKeyPermissionDao,
                permissionDao,
                lambda y: y.permission_id,
                obj_key="apikeyid",
            ),
        )
