package com.airlock.iam.flow.shared.application.configuration.condition;

import com.airlock.iam.core.misc.cronto.CrontoHandler;
import com.airlock.iam.flow.api.application.configuration.selection.FlowConditionConfig;
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 = "Condition that decides whether the user has an active Cronto device.", displayName = "Has Cronto Device")
@PluginLicenseRestriction(moduleAffiliation = "Cronto")
public final class HasCrontoDeviceConditionConfig implements FlowConditionConfig {
   @PluginProperty(description = "Plugin to handle all Cronto-specific actions.", globalPluginReference = "globalCrontoSettings", optional = false)
   private CrontoHandler crontoHandler;
   @BooleanProperty(
      description = "<p>If this flag is set and there is no push-enabled device for the user, authentication is not possible.</p><p>This feature may be used for mobile application logins, where showing a cryptogram on the same device is not appropriate.</p>",
      defaultValue = "false",
      optional = true
   )
   private boolean requirePushDevice;

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

   public boolean isRequirePushDevice() {
      return this.requirePushDevice;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public HasCrontoDeviceConditionConfig(CrontoHandler crontoHandler, boolean requirePushDevice) {
      this.crontoHandler = crontoHandler;
      this.requirePushDevice = requirePushDevice;
   }

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public HasCrontoDeviceConditionConfig.HasCrontoDeviceConditionConfigBuilder requirePushDevice(boolean requirePushDevice) {
         this.requirePushDevice = requirePushDevice;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "HasCrontoDeviceConditionConfig.HasCrontoDeviceConditionConfigBuilder(crontoHandler="
            + this.crontoHandler
            + ", requirePushDevice="
            + this.requirePushDevice
            + ")";
      }
   }
}
