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

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.IntegerProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Duration;
import java.util.Optional;

@Plugin(
   displayName = "Create Airlock 2FA Device Activation Letters",
   description = "<p>Settings for user's device activation letters. Such a letter contains a QR code to be scanned and is typically necessary for the registration of the first Airlock 2FA device.</p><p>Note that once the letter is generated, Airlock IAM is no longer involved in the activation of a user's device. This implies in particular, that a user who has been locked out after the generation of an activation letter could still use it to successfully register an Airlock 2FA device. Login will of course remain impossible as long the user is locked out.</p><p>Compared to \"Order Airlock 2FA Device Activation Letters\", no order will be created since activation letters will be directly generated by this plugin. The \"Airlock 2FA Activation Letter Order Task\" is therefore not necessary in this case.</p>"
)
@PluginLicenseRestriction(moduleAffiliation = "Airlock2FA")
public final class Airlock2FACreateActivationLettersConfig {
   public static final String CREATE_AIRLOCK_2FA_ACTIVATION_LETTERS_PLUGIN_NAME = "Create Airlock 2FA Device Activation Letters";
   @PluginProperty(description = "Configuration needed in case the created activation letter should be printed to a file.", optional = true)
   private Airlock2FAActivationLetterPrintingConfig letterPrintingOptions;
   @IntegerProperty(
      displayName = "Enrollment Validity [s]",
      description = "The duration (in seconds) an enrollment code should be valid.<p><b>Note:</b> This value is only used for the validity of the QR code in the enrollment letter and does not affect enrollment self-services.</p>",
      optional = true,
      exampleValues = 604800,
      defaultValue = 604800,
      minValue = 60,
      maxValue = 7776000
   )
   private int enrollmentValidityInSeconds;

   public Optional<Airlock2FAActivationLetterPrintingConfig> getLetterPrintingOptions() {
      return Optional.ofNullable(this.letterPrintingOptions);
   }

   public Duration getEnrollmentValidity() {
      return Duration.ofSeconds(this.enrollmentValidityInSeconds);
   }

   Airlock2FACreateActivationLettersConfig(Airlock2FAActivationLetterPrintingConfig letterPrintingOptions, int enrollmentValidityInSeconds) {
      this.letterPrintingOptions = letterPrintingOptions;
      this.enrollmentValidityInSeconds = enrollmentValidityInSeconds;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class Airlock2FACreateActivationLettersConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Airlock2FAActivationLetterPrintingConfig letterPrintingOptions;
      @SuppressFBWarnings(justification = "generated code")
      private int enrollmentValidityInSeconds;

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

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FACreateActivationLettersConfig.Airlock2FACreateActivationLettersConfigBuilder letterPrintingOptions(
         Airlock2FAActivationLetterPrintingConfig letterPrintingOptions
      ) {
         this.letterPrintingOptions = letterPrintingOptions;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FACreateActivationLettersConfig.Airlock2FACreateActivationLettersConfigBuilder enrollmentValidityInSeconds(int enrollmentValidityInSeconds) {
         this.enrollmentValidityInSeconds = enrollmentValidityInSeconds;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FACreateActivationLettersConfig build() {
         return new Airlock2FACreateActivationLettersConfig(this.letterPrintingOptions, this.enrollmentValidityInSeconds);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Airlock2FACreateActivationLettersConfig.Airlock2FACreateActivationLettersConfigBuilder(letterPrintingOptions="
            + this.letterPrintingOptions
            + ", enrollmentValidityInSeconds="
            + this.enrollmentValidityInSeconds
            + ")";
      }
   }
}
