// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.update.command;

import com.hypixel.hytale.server.core.HytaleServerConfig;
import com.hypixel.hytale.server.core.HytaleServer;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.update.UpdateService;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;

public class UpdatePatchlineCommand extends CommandBase
{
    public UpdatePatchlineCommand() {
        super("patchline", "server.commands.update.patchline.desc");
        this.addUsageVariant(new SetPatchlineVariant());
    }
    
    @Override
    protected void executeSync(@Nonnull final CommandContext context) {
        final String current = UpdateService.getEffectivePatchline();
        context.sendMessage(Message.translation("server.commands.update.patchline.current").param("patchline", current));
    }
    
    private static class SetPatchlineVariant extends CommandBase
    {
        @Nonnull
        private final RequiredArg<String> patchlineArg;
        
        SetPatchlineVariant() {
            super("server.commands.update.patchline.set.desc");
            this.patchlineArg = this.withRequiredArg("patchline", "server.commands.update.patchline.arg.desc", ArgTypes.STRING);
        }
        
        @Override
        protected void executeSync(@Nonnull final CommandContext context) {
            final String newPatchline = this.patchlineArg.get(context);
            final HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig();
            config.setPatchline(newPatchline);
            context.sendMessage(Message.translation("server.commands.update.patchline.changed").param("patchline", newPatchline));
        }
    }
}
