package com.newhive.scammerradar.commands.subcommands;

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

public class AddSubCommand extends SubCommand {
   private final ScammerRadarAddon addon;

   public AddSubCommand(ScammerRadarAddon addon) {
      super("add", 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 == 0) {
         this.addon.getHelper().displayNotification(I18n.translate("scammerradar.commands.add.usage", new Object[0]));
         return true;
      } else {
         try {
            String notice = arguments.length == 2 ? arguments[1] : "<no-notice>";
            this.addon.getHelper().addScammer(arguments[0], notice.replace("<no-notice>", ""));
            this.addon.getHelper().displayNotification(I18n.translate("scammerradar.commands.add.success", new Object[0]).replace("<user>", arguments[0]).replace("<notice>", notice.replace("<no-notice>", "-")));
         } catch (ProfileUpdateException | ProfileNotFoundException | IOException | ProfileAlreadyUsedException e) {
            this.addon.getHelper().displayNotification(e);
            this.addon.logger().error(((Exception)e).getMessage(), new Object[0]);
         }

         return true;
      }
   }
}
