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

import com.airlock.iam.flow.api.application.configuration.selection.FlowConditionConfig;
import com.airlock.iam.oauth2.api.application.configuration.provider.scope.OAuth2ScopeConditionConfig;
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.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "<p>Configures a OAuth 2.0 scope condition.</p><p>The scope is matched against the \"Scope Matcher\" pattern. A scope is allowed if it matches the regex and the condition is fulfilled.</p>",
   displayName = "Flow Condition-based OAuth 2.0 Scope Condition"
)
@PluginLicenseRestriction(moduleAffiliation = "OAuthServer")
public class FlowConditionBasedOAuth2ScopeConditionConfig implements OAuth2ScopeConditionConfig {
   @PluginProperty(description = "Matches the scope to check.", displayName = "Scope Matcher", optional = false)
   private OAuth2ScopeMatcherConfig scopeMatcher;
   public static final String SCOPE_MATCHER_DISPLAY_NAME = "Scope Matcher";
   @PluginProperty(
      description = "The condition that must be fulfilled. If the condition is not fulfilled, the scope is restricted and thus can not be granted.",
      optional = false
   )
   private FlowConditionConfig condition;

   public OAuth2ScopeMatcherConfig getScopeMatcher() {
      return this.scopeMatcher;
   }

   public FlowConditionConfig getCondition() {
      return this.condition;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public FlowConditionBasedOAuth2ScopeConditionConfig(OAuth2ScopeMatcherConfig scopeMatcher, FlowConditionConfig condition) {
      this.scopeMatcher = scopeMatcher;
      this.condition = condition;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class FlowConditionBasedOAuth2ScopeConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ScopeMatcherConfig scopeMatcher;
      @SuppressFBWarnings(justification = "generated code")
      private FlowConditionConfig condition;

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

      @SuppressFBWarnings(justification = "generated code")
      public FlowConditionBasedOAuth2ScopeConditionConfig.FlowConditionBasedOAuth2ScopeConditionConfigBuilder scopeMatcher(
         OAuth2ScopeMatcherConfig scopeMatcher
      ) {
         this.scopeMatcher = scopeMatcher;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public FlowConditionBasedOAuth2ScopeConditionConfig.FlowConditionBasedOAuth2ScopeConditionConfigBuilder condition(FlowConditionConfig condition) {
         this.condition = condition;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public FlowConditionBasedOAuth2ScopeConditionConfig build() {
         return new FlowConditionBasedOAuth2ScopeConditionConfig(this.scopeMatcher, this.condition);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "FlowConditionBasedOAuth2ScopeConditionConfig.FlowConditionBasedOAuth2ScopeConditionConfigBuilder(scopeMatcher="
            + this.scopeMatcher
            + ", condition="
            + this.condition
            + ")";
      }
   }
}
