package net.minecraft.commands.synchronization.brigadier;

import com.mojang.brigadier.arguments.ArgumentType;
import com.google.gson.JsonObject;
import net.minecraft.network.FriendlyByteBuf;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import net.minecraft.commands.synchronization.ArgumentSerializer;

public class DoubleArgumentSerializer implements ArgumentSerializer<DoubleArgumentType> {
    @Override
    public void serializeToNetwork(final DoubleArgumentType doubleArgumentType, final FriendlyByteBuf mg) {
        final boolean boolean4 = doubleArgumentType.getMinimum() != -1.7976931348623157E308;
        final boolean boolean5 = doubleArgumentType.getMaximum() != Double.MAX_VALUE;
        mg.writeByte(BrigadierArgumentSerializers.createNumberFlags(boolean4, boolean5));
        if (boolean4) {
            mg.writeDouble(doubleArgumentType.getMinimum());
        }
        if (boolean5) {
            mg.writeDouble(doubleArgumentType.getMaximum());
        }
    }
    
    @Override
    public DoubleArgumentType deserializeFromNetwork(final FriendlyByteBuf mg) {
        final byte byte3 = mg.readByte();
        final double double4 = BrigadierArgumentSerializers.numberHasMin(byte3) ? mg.readDouble() : -1.7976931348623157E308;
        final double double5 = BrigadierArgumentSerializers.numberHasMax(byte3) ? mg.readDouble() : Double.MAX_VALUE;
        return DoubleArgumentType.doubleArg(double4, double5);
    }
    
    @Override
    public void serializeToJson(final DoubleArgumentType doubleArgumentType, final JsonObject jsonObject) {
        if (doubleArgumentType.getMinimum() != -1.7976931348623157E308) {
            jsonObject.addProperty("min", doubleArgumentType.getMinimum());
        }
        if (doubleArgumentType.getMaximum() != Double.MAX_VALUE) {
            jsonObject.addProperty("max", doubleArgumentType.getMaximum());
        }
    }
}
