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

import com.airlock.iam.factor.application.configuration.airlock2fa.Airlock2FASettings;
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 determines whether the current user is allowed to delete an Airlock 2FA app device. For device deletion to be possible, the user needs to have at least one app device. If \"Allow Deleting All Devices\" is disabled, at least two app devices are required. This is to ensure that the user will still be able to log in with Airlock 2FA after device deletion was performed.",
   displayName = "Airlock 2FA Device Deletion Possible"
)
@PluginLicenseRestriction(moduleAffiliation = "Airlock2FA")
public final class Airlock2FADeviceDeletionPossibleConditionConfig implements FlowConditionConfig {
   static final String ALLOW_DELETING_ALL_DEVICES_DISPLAY_NAME = "Allow Deleting All Devices";
   public static final String AIRLOCK_2FA_DEVICE_DELETION_POSSIBLE_CONDITION_DISPLAY_NAME = "Airlock 2FA Device Deletion Possible";
   @PluginProperty(
      displayName = "Airlock 2FA Settings",
      description = "Settings of Airlock 2FA.",
      optional = false,
      globalPluginReference = "globalAirlock2FASettings"
   )
   private Airlock2FASettings airlock2faSettings;
   @BooleanProperty(
      description = "If this option is enabled, a user may delete all his Airlock 2FA app devices. In this case, the user will no longer be able to log in with Airlock 2FA unless he/she is in possession of an Airlock 2FA hardware device. Note that a user cannot delete assigned Airlock 2FA hardware-devices and so this setting affects only app devices.",
      optional = true,
      defaultValue = "false",
      displayName = "Allow Deleting All Devices"
   )
   private boolean canUserDeleteAllDevices;

   public Airlock2FASettings getAirlock2faSettings() {
      return this.airlock2faSettings;
   }

   public boolean isCanUserDeleteAllDevices() {
      return this.canUserDeleteAllDevices;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public Airlock2FADeviceDeletionPossibleConditionConfig(Airlock2FASettings airlock2faSettings, boolean canUserDeleteAllDevices) {
      this.airlock2faSettings = airlock2faSettings;
      this.canUserDeleteAllDevices = canUserDeleteAllDevices;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class Airlock2FADeviceDeletionPossibleConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Airlock2FASettings airlock2faSettings;
      @SuppressFBWarnings(justification = "generated code")
      private boolean canUserDeleteAllDevices;

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

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FADeviceDeletionPossibleConditionConfig.Airlock2FADeviceDeletionPossibleConditionConfigBuilder airlock2faSettings(
         Airlock2FASettings airlock2faSettings
      ) {
         this.airlock2faSettings = airlock2faSettings;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FADeviceDeletionPossibleConditionConfig.Airlock2FADeviceDeletionPossibleConditionConfigBuilder canUserDeleteAllDevices(
         boolean canUserDeleteAllDevices
      ) {
         this.canUserDeleteAllDevices = canUserDeleteAllDevices;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FADeviceDeletionPossibleConditionConfig build() {
         return new Airlock2FADeviceDeletionPossibleConditionConfig(this.airlock2faSettings, this.canUserDeleteAllDevices);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Airlock2FADeviceDeletionPossibleConditionConfig.Airlock2FADeviceDeletionPossibleConditionConfigBuilder(airlock2faSettings="
            + this.airlock2faSettings
            + ", canUserDeleteAllDevices="
            + this.canUserDeleteAllDevices
            + ")";
      }
   }
}
