package com.newhive.scammerradar.commands.subcommands;

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

public class CheckSubCommand extends SubCommand {
   private final ScammerRadarAddon addon;

   public CheckSubCommand(ScammerRadarAddon addon) {
      super("check", 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.check.usage", new Object[0]));
         return true;
      } else {
         try {
            TextComponent result = arguments[0].equals("*") ? this.addon.getHelper().doCheck((String)null) : this.addon.getHelper().doCheck(arguments[0]);
            this.addon.getHelper().displayNotification(result);
         } catch (IOException | ProfileUpdateException e) {
            this.addon.getHelper().displayNotification(e);
            this.addon.logger().error(((Exception)e).getMessage(), new Object[0]);
         }

         return true;
      }
   }
}
