package de.dhbwstuttgart.typeinference.result;

import de.dhbwstuttgart.server.packet.dataContainers.ISerializableData;
import de.dhbwstuttgart.server.packet.dataContainers.KeyStorage;
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialMap;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.UnifyContext;

public class PairTPHEqualTPH extends ResultPair<TypePlaceholder, TypePlaceholder> implements ISerializableData {
    public PairTPHEqualTPH(TypePlaceholder tl, TypePlaceholder tr) {
        super(tl, tr);
    }

    @Override
    public void accept(ResultPairVisitor visitor) {
        visitor.visit(this);
    }

    @Override
    public SerialMap toSerial(KeyStorage keyStorage) {
        SerialMap serialized = new SerialMap();
        serialized.put("left", this.getLeft().toSerial(keyStorage));
        serialized.put("right", this.getRight().toSerial(keyStorage));
        // create the wrapper and put this as the object
        var serializedWrapper = super.toSerial(keyStorage);
        serializedWrapper.put("object", serialized);
        return serializedWrapper;
    }

    public static PairTPHEqualTPH fromSerial2(SerialMap data, UnifyContext context) {
        SerialMap left = data.getMap("left");
        SerialMap right = data.getMap("right");
        return new PairTPHEqualTPH(
          (TypePlaceholder) RefTypeOrTPHOrWildcardOrGeneric.fromSerial(left, context),
          (TypePlaceholder) RefTypeOrTPHOrWildcardOrGeneric.fromSerial(right, context)
        );
    }
}
