package com.newhive.scammerradar.commands.subcommands;

import com.newhive.scammerradar.ScammerRadarAddon;
import com.newhive.scammerradar.config.ScammerRadarConfig;
import com.newhive.scammerradar.exceptions.ProfileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.util.I18n;

public class EditSubCommand extends SubCommand {
   private final ScammerRadarAddon addon;

   public EditSubCommand(ScammerRadarAddon addon) {
      super("edit", new String[0]);
      this.addon = addon;
   }

   public boolean execute(String prefix, String[] arguments) {
      if (!(Boolean)((ScammerRadarConfig)this.addon.configuration()).enabled().get()) {
         return false;
      } else {
         if (arguments.length >= 2) {
            try {
               List<String> notice = new ArrayList(Arrays.asList(arguments));
               notice.remove(0);
               this.addon.getHelper().editScammer(arguments[0], String.join(" ", notice));
               this.addon.getHelper().displayNotification(I18n.translate("scammerradar.commands.edit.success", new Object[0]).replace("<user>", arguments[0]));
            } catch (IOException | ProfileNotFoundException e) {
               this.addon.getHelper().displayNotification(e);
               this.addon.logger().error(((Exception)e).getMessage(), new Object[0]);
            }
         } else {
            this.addon.getHelper().displayNotification(I18n.translate("scammerradar.commands.edit.usage", new Object[0]));
         }

         return true;
      }
   }
}
