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.IntegerArgumentType;
import net.minecraft.commands.synchronization.ArgumentSerializer;

public class IntegerArgumentSerializer implements ArgumentSerializer<IntegerArgumentType> {
    @Override
    public void serializeToNetwork(final IntegerArgumentType integerArgumentType, final FriendlyByteBuf mg) {
        final boolean boolean4 = integerArgumentType.getMinimum() != Integer.MIN_VALUE;
        final boolean boolean5 = integerArgumentType.getMaximum() != Integer.MAX_VALUE;
        mg.writeByte(BrigadierArgumentSerializers.createNumberFlags(boolean4, boolean5));
        if (boolean4) {
            mg.writeInt(integerArgumentType.getMinimum());
        }
        if (boolean5) {
            mg.writeInt(integerArgumentType.getMaximum());
        }
    }
    
    @Override
    public IntegerArgumentType deserializeFromNetwork(final FriendlyByteBuf mg) {
        final byte byte3 = mg.readByte();
        final int integer4 = BrigadierArgumentSerializers.numberHasMin(byte3) ? mg.readInt() : Integer.MIN_VALUE;
        final int integer5 = BrigadierArgumentSerializers.numberHasMax(byte3) ? mg.readInt() : Integer.MAX_VALUE;
        return IntegerArgumentType.integer(integer4, integer5);
    }
    
    @Override
    public void serializeToJson(final IntegerArgumentType integerArgumentType, final JsonObject jsonObject) {
        if (integerArgumentType.getMinimum() != Integer.MIN_VALUE) {
            jsonObject.addProperty("min", integerArgumentType.getMinimum());
        }
        if (integerArgumentType.getMaximum() != Integer.MAX_VALUE) {
            jsonObject.addProperty("max", integerArgumentType.getMaximum());
        }
    }
}
