package com.airlock.iam.oauth2.application.configuration.accountlinking;

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.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;

@Plugin(description = "Allows users to manage a link to their account of the provider.")
@PluginLicenseRestriction(moduleAffiliation = {"OAuthAccountLinking", "OAuthSocialRegistration"})
public final class AccountLinkingSelfServiceConfig {
   public static final String ACCOUNT_INFO_RESOURCE_KEY_DISPLAY_NAME = "Account Info Resource Key";
   @BooleanProperty(
      description = "If enabled, an additional confirmation page is shown when a user starts linking a new account before being redirected to the external provider for authentication.",
      displayName = "Ask For Confirmation Before Linking",
      defaultValue = "true",
      optional = true
   )
   private boolean askForConfirmationBeforeLinking;
   @StringProperty(
      description = "Defines a resource key that is used to look up and display additional data of a linked account on the account link management page. To obtain the data, it is required to add an 'OAuth 2.0 Remote Context Data Resource' with a 'Local Context Data Key' equal to this resource key to the resource mappings. Please note that the remote data might only be available if it was requested with the corresponding scope from the authorization endpoint.<br>This property is helpful to display data that uniquely and understandably identifies an account, e.g. to display the user's email if available.",
      suggestedValues = "email",
      displayName = "Account Info Resource Key",
      optional = true
   )
   private String accountInfo;

   public Optional<String> getAccountInfo() {
      return Optional.ofNullable(this.accountInfo);
   }

   public boolean isAskForConfirmationBeforeLinking() {
      return this.askForConfirmationBeforeLinking;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public AccountLinkingSelfServiceConfig(boolean askForConfirmationBeforeLinking, String accountInfo) {
      this.askForConfirmationBeforeLinking = askForConfirmationBeforeLinking;
      this.accountInfo = accountInfo;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class AccountLinkingSelfServiceConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private boolean askForConfirmationBeforeLinking;
      @SuppressFBWarnings(justification = "generated code")
      private String accountInfo;

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

      @SuppressFBWarnings(justification = "generated code")
      public AccountLinkingSelfServiceConfig.AccountLinkingSelfServiceConfigBuilder askForConfirmationBeforeLinking(boolean askForConfirmationBeforeLinking) {
         this.askForConfirmationBeforeLinking = askForConfirmationBeforeLinking;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public AccountLinkingSelfServiceConfig.AccountLinkingSelfServiceConfigBuilder accountInfo(String accountInfo) {
         this.accountInfo = accountInfo;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public AccountLinkingSelfServiceConfig build() {
         return new AccountLinkingSelfServiceConfig(this.askForConfirmationBeforeLinking, this.accountInfo);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "AccountLinkingSelfServiceConfig.AccountLinkingSelfServiceConfigBuilder(askForConfirmationBeforeLinking="
            + this.askForConfirmationBeforeLinking
            + ", accountInfo="
            + this.accountInfo
            + ")";
      }
   }
}
