package com.airlock.iam.admin.application.configuration.tokens.vasco;

import com.airlock.iam.admin.application.configuration.tokens.TokenManager;
import com.airlock.iam.core.misc.persistency.token.TokenDataProvider;
import com.airlock.iam.core.misc.util.vasco.VascoHandler;
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 = "A token manager for Vasco Digipass OTP (response only) tokens.", displayName = "Vasco OTP Token Manager")
@PluginLicenseRestriction(moduleAffiliation = "Digipass")
public class VascoOtpTokenManager implements TokenManager {
   public static final String VASCO_OTP_TOKEN_MANAGER_DISPLAY_NAME = "Vasco OTP Token Manager";
   @PluginProperty(
      description = "The token data provider loads, saves and updates token on the persistence layer.",
      optional = false,
      globalPluginReference = "globalTokenDataProvider"
   )
   private TokenDataProvider tokenDataProvider;
   @PluginProperty(description = "The Vasco handler provides access to the Vacman Controller native library.", optional = false)
   private VascoHandler vascoHandler;
   @BooleanProperty(
      description = "If set to true, imported tokens are enabled immediately. Otherwise, they remain disabled.",
      optional = true,
      defaultValue = "true"
   )
   private boolean enableImportedTokens;

   @Override
   public TokenDataProvider getTokenDataProvider() {
      return this.tokenDataProvider;
   }

   public VascoHandler getVascoHandler() {
      return this.vascoHandler;
   }

   public boolean isEnableImportedTokens() {
      return this.enableImportedTokens;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public VascoOtpTokenManager(TokenDataProvider tokenDataProvider, VascoHandler vascoHandler, boolean enableImportedTokens) {
      this.tokenDataProvider = tokenDataProvider;
      this.vascoHandler = vascoHandler;
      this.enableImportedTokens = enableImportedTokens;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class VascoOtpTokenManagerBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private TokenDataProvider tokenDataProvider;
      @SuppressFBWarnings(justification = "generated code")
      private VascoHandler vascoHandler;
      @SuppressFBWarnings(justification = "generated code")
      private boolean enableImportedTokens;

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

      @SuppressFBWarnings(justification = "generated code")
      public VascoOtpTokenManager.VascoOtpTokenManagerBuilder tokenDataProvider(TokenDataProvider tokenDataProvider) {
         this.tokenDataProvider = tokenDataProvider;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public VascoOtpTokenManager.VascoOtpTokenManagerBuilder vascoHandler(VascoHandler vascoHandler) {
         this.vascoHandler = vascoHandler;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public VascoOtpTokenManager.VascoOtpTokenManagerBuilder enableImportedTokens(boolean enableImportedTokens) {
         this.enableImportedTokens = enableImportedTokens;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public VascoOtpTokenManager build() {
         return new VascoOtpTokenManager(this.tokenDataProvider, this.vascoHandler, this.enableImportedTokens);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "VascoOtpTokenManager.VascoOtpTokenManagerBuilder(tokenDataProvider="
            + this.tokenDataProvider
            + ", vascoHandler="
            + this.vascoHandler
            + ", enableImportedTokens="
            + this.enableImportedTokens
            + ")";
      }
   }
}
