from typing import (
    List,
)

from ._UpdatableEntity import UpdatableEntity


class UpdatableList(object):
    def __init__(self, values: List[UpdatableEntity]):
        self._map = {}
        for value in values:
            self._map[id(value)] = value

    def values(self):
        return list(self._map.values())

    def update(self, new_values: List[UpdatableEntity]):
        remaining_ids = set(self._map.keys())
        for new_values in new_values:
            if id(new_values) in self._map:
                self._map[id(new_values)].update(new_data=new_values)
                remaining_ids.remove(id(new_values))
            else:
                self._map[id(new_values)] = new_values

        for remaining_id in remaining_ids:
            del self._map[remaining_id]
