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

public class StringArgumentSerializer implements ArgumentSerializer<StringArgumentType> {
    @Override
    public void serializeToNetwork(final StringArgumentType stringArgumentType, final FriendlyByteBuf kv) {
        kv.writeEnum(stringArgumentType.getType());
    }
    
    @Override
    public StringArgumentType deserializeFromNetwork(final FriendlyByteBuf kv) {
        final StringArgumentType.StringType stringType3 = kv.<StringArgumentType.StringType>readEnum(StringArgumentType.StringType.class);
        switch (stringType3) {
            case SINGLE_WORD: {
                return StringArgumentType.word();
            }
            case QUOTABLE_PHRASE: {
                return StringArgumentType.string();
            }
            default: {
                return StringArgumentType.greedyString();
            }
        }
    }
    
    @Override
    public void serializeToJson(final StringArgumentType stringArgumentType, final JsonObject jsonObject) {
        switch (stringArgumentType.getType()) {
            case SINGLE_WORD: {
                jsonObject.addProperty("type", "word");
                break;
            }
            case QUOTABLE_PHRASE: {
                jsonObject.addProperty("type", "phrase");
                break;
            }
            default: {
                jsonObject.addProperty("type", "greedy");
                break;
            }
        }
    }
}
