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

public class LongArgumentSerializer implements ArgumentSerializer<LongArgumentType> {
    @Override
    public void serializeToNetwork(final LongArgumentType longArgumentType, final FriendlyByteBuf kv) {
        final boolean boolean4 = longArgumentType.getMinimum() != Long.MIN_VALUE;
        final boolean boolean5 = longArgumentType.getMaximum() != Long.MAX_VALUE;
        kv.writeByte(BrigadierArgumentSerializers.createNumberFlags(boolean4, boolean5));
        if (boolean4) {
            kv.writeLong(longArgumentType.getMinimum());
        }
        if (boolean5) {
            kv.writeLong(longArgumentType.getMaximum());
        }
    }
    
    @Override
    public LongArgumentType deserializeFromNetwork(final FriendlyByteBuf kv) {
        final byte byte3 = kv.readByte();
        final long long4 = BrigadierArgumentSerializers.numberHasMin(byte3) ? kv.readLong() : Long.MIN_VALUE;
        final long long5 = BrigadierArgumentSerializers.numberHasMax(byte3) ? kv.readLong() : Long.MAX_VALUE;
        return LongArgumentType.longArg(long4, long5);
    }
    
    @Override
    public void serializeToJson(final LongArgumentType longArgumentType, final JsonObject jsonObject) {
        if (longArgumentType.getMinimum() != Long.MIN_VALUE) {
            jsonObject.addProperty("min", longArgumentType.getMinimum());
        }
        if (longArgumentType.getMaximum() != Long.MAX_VALUE) {
            jsonObject.addProperty("max", longArgumentType.getMaximum());
        }
    }
}
