package com.airlock.iam.admin.application.configuration.cronto;

import com.airlock.iam.admin.api.domain.model.user.AuthenticationMethods;
import com.airlock.iam.admin.domain.model.token.TokenController;
import com.airlock.iam.core.misc.cronto.CrontoHandler;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.license.PluginLicenseRestriction;
import com.airlock.iam.plugin.api.annotation.property.BooleanProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "Plugin to manage a user's Cronto tokens.")
@PluginLicenseRestriction(moduleAffiliation = "Cronto")
public class CrontoTokenController implements TokenController {
   @TokenController.TokenControllerId
   public static final String ID = "CRONTO";
   @PluginProperty(description = "Plugin to manage a user's Cronto tokens.", optional = false, globalPluginReference = "globalCrontoSettings")
   private CrontoHandler crontoHandler;
   @BooleanProperty(
      description = "Auto order an activation letter upon adding this credential to the user. Note that if no default order options are set in the Cronto Handler plugin, the letter is only generated but not printed.",
      optional = true,
      defaultValue = "false"
   )
   private boolean autoOrder;

   public CrontoTokenController(CrontoHandler crontoHandler, boolean autoOrder) {
      this.crontoHandler = crontoHandler;
      this.autoOrder = autoOrder;
   }

   @Override
   public AuthenticationMethods.AuthenticationMethodId getConfiguredId() {
      return AuthenticationMethods.AuthenticationMethodId.authMethodId("CRONTO");
   }

   @Override
   public String getTokenControllerId() {
      return "CRONTO";
   }

   public CrontoHandler getCrontoHandler() {
      return this.crontoHandler;
   }

   public boolean isAutoOrder() {
      return this.autoOrder;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static CrontoTokenController.CrontoTokenControllerBuilder builder() {
      return new CrontoTokenController.CrontoTokenControllerBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public CrontoTokenController() {
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class CrontoTokenControllerBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private CrontoHandler crontoHandler;
      @SuppressFBWarnings(justification = "generated code")
      private boolean autoOrder;

      @SuppressFBWarnings(justification = "generated code")
      CrontoTokenControllerBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoTokenController.CrontoTokenControllerBuilder crontoHandler(CrontoHandler crontoHandler) {
         this.crontoHandler = crontoHandler;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoTokenController.CrontoTokenControllerBuilder autoOrder(boolean autoOrder) {
         this.autoOrder = autoOrder;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoTokenController build() {
         return new CrontoTokenController(this.crontoHandler, this.autoOrder);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "CrontoTokenController.CrontoTokenControllerBuilder(crontoHandler=" + this.crontoHandler + ", autoOrder=" + this.autoOrder + ")";
      }
   }
}
