from api_graphql.abc.db_history_model_query_abc import DbHistoryModelQueryABC
from data.schemas.permission.role_dao import roleDao
from data.schemas.permission.role_user_dao import roleUserDao


class UserHistoryQuery(DbHistoryModelQueryABC):
    def __init__(self):
        DbHistoryModelQueryABC.__init__(self, "User")

        self.set_field("keycloakId", lambda x, *_: x.keycloak_id)
        self.set_field("username", lambda x, *_: x.username)
        self.set_field("email", lambda x, *_: x.email)
        self.set_field(
            "roles",
            lambda x, *_: self._resolve_foreign_history(
                x.updated,
                x.id,
                roleUserDao,
                roleDao,
                lambda y: y.role_id,
                obj_key="userid",
            ),
        )
