package com.airlock.iam.login.rest.application.configuration;

import com.airlock.iam.core.misc.authen.PasswordSettings;
import com.airlock.iam.login.application.configuration.mtan.MtanSelfManagementConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
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;
import java.util.Optional;

@Plugin(
   description = "<p>\n\tSettings for session-less user self-services. In contrast to the \"Protected Self-Services\"\n\tthese self-services don't require an authenticated session. Instead, each request must contain authentication\n\tinformation, as defined by the \"API Access Control\" settings.\n</p>\n<p>\n\tThese REST endpoints begin with the resource path <code>/&lt;loginapp-uri&gt;/rest/protected/my/</code>.\n</p>\n",
   displayName = "User Self-Service Settings"
)
public class UserSelfServiceConfig {
   public static final String USER_SELF_SERVICE_SETTINGS_DISPLAY_NAME = "User Self-Service Settings";
   @PluginProperty(
      description = "<p>\n\tConfigures the session-less password change REST endpoint\n\t<code>/&lt;loginapp-uri&gt;/rest/protected/my/password/change/</code> by using the \"Password Service\" and\n\tthe \"Password Policy\" plugins from the referenced \"Password Settings\" plugin.\n</p>\n<p>\n\t<b>Deprecated</b>: The session-less password self-service endpoints are deprecated and will be removed in a future IAM version.\n       Use protected self-service flows instead.\n</p>\n",
      optional = true
   )
   private PasswordSettings passwordSettings;
   @BooleanProperty(
      description = "<p>Enables the public REST endpoint to check passwords against the policy configured in the configured \"Password Settings\" plugin.<br/>\nPassword policy checks are not applicable when using end-to-end encrypted passwords.</p>\n<p>REST endpoint: <code>/&lt;loginapp-uri&gt;/rest/public/password/policy/check/</code></p>\n",
      optional = true,
      defaultValue = "false"
   )
   private boolean enablePasswordPolicyCheck;
   @PluginProperty(
      description = "Configures the protected session-less REST endpoint <code>/&lt;loginapp-uri&gt;/rest/protected/my/self/</code>.",
      optional = true,
      displayName = "User Information Self-Service"
   )
   private UserSelfInformationConfig userInformationSelfService;
   static final String USER_INFORMATION_SELF_SERVICE_NAME = "userInformationSelfService";
   @PluginProperty(
      description = "<p>\n\tConfigures the protected session-less REST endpoints used to manage mobile phone numbers for mTAN authentication.\n</p>\n<p>\n\tREST endpoints: <code>/&lt;loginapp-uri&gt;/rest/protected/my/tokens/mtan/*</code>\n</p>\n<p>\n\t<b>Deprecated</b>: The session-less mTAN self-service endpoints are deprecated and will be removed in a future IAM version.\n       Use protected self-service flows instead.\n</p>\n",
      optional = true,
      displayName = "mTAN Self-Service (Legacy)"
   )
   private MtanSelfManagementConfig mtanSelfService;
   @PluginProperty(
      description = "<p>\n\tConfigures the protected session-less REST endpoints used to manage Cronto tokens.\n</p>\n<p>\n\tREST endpoints: <code>/&lt;loginapp-uri&gt;/rest/protected/my/tokens/cronto/*</code>\n</p>\n<p>\n\t<b>Deprecated</b>: The session-less Cronto self-service endpoints are deprecated and will be removed in a future IAM version.\n       Use protected self-service flows instead.\n</p>\n",
      optional = true,
      displayName = "Cronto Self-Service (Legacy)"
   )
   private CrontoSelfServiceRestConfig crontoSelfService;

   public Optional<PasswordSettings> getPasswordSettings() {
      return Optional.ofNullable(this.passwordSettings);
   }

   public Optional<MtanSelfManagementConfig> getMtanSelfService() {
      return Optional.ofNullable(this.mtanSelfService);
   }

   public Optional<CrontoSelfServiceRestConfig> getCrontoSelfService() {
      return Optional.ofNullable(this.crontoSelfService);
   }

   public Optional<UserSelfInformationConfig> getUserInformationSelfService() {
      return Optional.ofNullable(this.userInformationSelfService);
   }

   public boolean isEnablePasswordPolicyCheck() {
      return this.enablePasswordPolicyCheck;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public UserSelfServiceConfig(
      PasswordSettings passwordSettings,
      boolean enablePasswordPolicyCheck,
      UserSelfInformationConfig userInformationSelfService,
      MtanSelfManagementConfig mtanSelfService,
      CrontoSelfServiceRestConfig crontoSelfService
   ) {
      this.passwordSettings = passwordSettings;
      this.enablePasswordPolicyCheck = enablePasswordPolicyCheck;
      this.userInformationSelfService = userInformationSelfService;
      this.mtanSelfService = mtanSelfService;
      this.crontoSelfService = crontoSelfService;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class UserSelfServiceConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private PasswordSettings passwordSettings;
      @SuppressFBWarnings(justification = "generated code")
      private boolean enablePasswordPolicyCheck;
      @SuppressFBWarnings(justification = "generated code")
      private UserSelfInformationConfig userInformationSelfService;
      @SuppressFBWarnings(justification = "generated code")
      private MtanSelfManagementConfig mtanSelfService;
      @SuppressFBWarnings(justification = "generated code")
      private CrontoSelfServiceRestConfig crontoSelfService;

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

      @SuppressFBWarnings(justification = "generated code")
      public UserSelfServiceConfig.UserSelfServiceConfigBuilder passwordSettings(PasswordSettings passwordSettings) {
         this.passwordSettings = passwordSettings;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserSelfServiceConfig.UserSelfServiceConfigBuilder enablePasswordPolicyCheck(boolean enablePasswordPolicyCheck) {
         this.enablePasswordPolicyCheck = enablePasswordPolicyCheck;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserSelfServiceConfig.UserSelfServiceConfigBuilder userInformationSelfService(UserSelfInformationConfig userInformationSelfService) {
         this.userInformationSelfService = userInformationSelfService;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserSelfServiceConfig.UserSelfServiceConfigBuilder mtanSelfService(MtanSelfManagementConfig mtanSelfService) {
         this.mtanSelfService = mtanSelfService;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserSelfServiceConfig.UserSelfServiceConfigBuilder crontoSelfService(CrontoSelfServiceRestConfig crontoSelfService) {
         this.crontoSelfService = crontoSelfService;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserSelfServiceConfig build() {
         return new UserSelfServiceConfig(
            this.passwordSettings, this.enablePasswordPolicyCheck, this.userInformationSelfService, this.mtanSelfService, this.crontoSelfService
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "UserSelfServiceConfig.UserSelfServiceConfigBuilder(passwordSettings="
            + this.passwordSettings
            + ", enablePasswordPolicyCheck="
            + this.enablePasswordPolicyCheck
            + ", userInformationSelfService="
            + this.userInformationSelfService
            + ", mtanSelfService="
            + this.mtanSelfService
            + ", crontoSelfService="
            + this.crontoSelfService
            + ")";
      }
   }
}
