from api_graphql.abc.db_history_model_query_abc import DbHistoryModelQueryABC
from data.schemas.administration.user_dao import userDao
from data.schemas.public.user_space_user_dao import userSpaceUserDao


class UserSpaceHistoryQuery(DbHistoryModelQueryABC):
    def __init__(self):
        DbHistoryModelQueryABC.__init__(self, "UserSpace")

        self.set_field("name", lambda x, *_: x.name)
        self.set_field("owner", lambda x, *_: x.owner)
        self.set_field(
            "users",
            lambda x, *_: self._resolve_foreign_history(
                x.updated,
                x.id,
                userSpaceUserDao,
                userDao,
                lambda y: y.user_id,
                obj_key="userspaceid",
            ),
        )
