package leigh.elements;

import leigh.elements.sdk.AppScreenInstance;
import leigh.elements.sdk.ElementFactory;
import leigh.elements.sdk.type1.Element;
import leigh.eo.EO;

import java.util.UUID;
import java.util.WeakHashMap;

public abstract class ElementsFactoryBase implements ElementFactory {
    private final WeakHashMap<UUID, Element> elements = new WeakHashMap<>();

    @Override
    public Element build(EO cfg, AppScreenInstance screen) {
        Element element = newNode(cfg, screen);
        UUID id = cfg.getValueUUID(Element.KEY_ID);

        assert (element != null);
      //  assert (id != null);

        elements.put(id, element);

        return element;
    }

    public abstract Element newNode(EO cfg, AppScreenInstance screen);

    public Element getElement(UUID id) {
        return elements.get(id);
    }
}
