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;

/**
 * Steht für A =. RefType
 */
public class PairTPHequalRefTypeOrWildcardType extends ResultPair<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric>
implements ISerializableData {
    public final TypePlaceholder left;
    public final RefTypeOrTPHOrWildcardOrGeneric right;

    public PairTPHequalRefTypeOrWildcardType(TypePlaceholder left, RefTypeOrTPHOrWildcardOrGeneric right){
        super(left, right);
        this.left = left;
        this.right = right;
    }

    @Override
    public void accept(ResultPairVisitor visitor) {
        visitor.visit(this);
    }
    
    @Override
    public String toString() {
    	return "(" + left.toString() + " = " + right.toString() + ")";
    }

    @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 PairTPHequalRefTypeOrWildcardType fromSerial2(SerialMap data, UnifyContext context) {
        SerialMap left = data.getMap("left");
        SerialMap right = data.getMap("right");
        return new PairTPHequalRefTypeOrWildcardType(
          (TypePlaceholder)RefTypeOrTPHOrWildcardOrGeneric.fromSerial(left, context),
          RefTypeOrTPHOrWildcardOrGeneric.fromSerial(right, context)
        );
    }
}
