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

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.RegexProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.regex.Pattern;

@Plugin(
   displayName = "OAuth 2.0 Custom Session Attribute",
   description = "Configuration of an OAuth 2.0 custom session attribute.<p>An OAuth 2.0 session can have various custom attributes that are defined as a name-value pair.</p>"
)
@PluginLicenseRestriction(moduleAffiliation = "OAuthServer")
public class OAuth2CustomSessionAttributeConfig {
   @StringProperty(description = "Name of the OAuth 2.0 custom session attribute.", optional = false, maxLength = 50)
   private String name;
   @RegexProperty(description = "An optional regular expression to validate the value.", optional = true, defaultValue = ".{1,200}")
   private Pattern valuePattern;
   @BooleanProperty(
      description = "Whether the value of this OAuth 2.0 custom session attribute can be updated after being set once. If unchecked, the OAuth 2.0 custom session attribute can only be created once but never be updated nor deleted.",
      optional = true,
      defaultValue = "true"
   )
   private boolean updatable;

   public String getName() {
      return this.name;
   }

   public Pattern getValuePattern() {
      return this.valuePattern;
   }

   public boolean isUpdatable() {
      return this.updatable;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public OAuth2CustomSessionAttributeConfig(String name, Pattern valuePattern, boolean updatable) {
      this.name = name;
      this.valuePattern = valuePattern;
      this.updatable = updatable;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class OAuth2CustomSessionAttributeConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String name;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern valuePattern;
      @SuppressFBWarnings(justification = "generated code")
      private boolean updatable;

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

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2CustomSessionAttributeConfig.OAuth2CustomSessionAttributeConfigBuilder name(String name) {
         this.name = name;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2CustomSessionAttributeConfig.OAuth2CustomSessionAttributeConfigBuilder valuePattern(Pattern valuePattern) {
         this.valuePattern = valuePattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2CustomSessionAttributeConfig.OAuth2CustomSessionAttributeConfigBuilder updatable(boolean updatable) {
         this.updatable = updatable;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2CustomSessionAttributeConfig build() {
         return new OAuth2CustomSessionAttributeConfig(this.name, this.valuePattern, this.updatable);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "OAuth2CustomSessionAttributeConfig.OAuth2CustomSessionAttributeConfigBuilder(name="
            + this.name
            + ", valuePattern="
            + this.valuePattern
            + ", updatable="
            + this.updatable
            + ")";
      }
   }
}
