package net.minecraft.data.models.blockstates;

import com.google.gson.JsonArray;
import java.util.List;
import com.google.gson.JsonObject;
import com.google.common.collect.Maps;
import java.util.Map;
import com.google.gson.JsonElement;
import java.util.function.Supplier;

public class Variant implements Supplier<JsonElement> {
    private final Map<VariantProperty<?>, VariantProperty.Value> values;
    
    public Variant() {
        this.values = Maps.newLinkedHashMap();
    }
    
    public <T> Variant with(final VariantProperty<T> is, final T object) {
        final VariantProperty.Value a4 = this.values.put(is, is.withValue(object));
        if (a4 != null) {
            throw new IllegalStateException("Replacing value of " + a4 + " with " + object);
        }
        return this;
    }
    
    public static Variant variant() {
        return new Variant();
    }
    
    public static Variant merge(final Variant iq1, final Variant iq2) {
        final Variant iq3 = new Variant();
        iq3.values.putAll(iq1.values);
        iq3.values.putAll(iq2.values);
        return iq3;
    }
    
    @Override
    public JsonElement get() {
        final JsonObject jsonObject2 = new JsonObject();
        this.values.values().forEach(a -> a.addToVariant(jsonObject2));
        return jsonObject2;
    }
    
    public static JsonElement convertList(final List<Variant> list) {
        if (list.size() == 1) {
            return list.get(0).get();
        }
        final JsonArray jsonArray2 = new JsonArray();
        list.forEach(iq -> jsonArray2.add(iq.get()));
        return jsonArray2;
    }
}
