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

import com.airlock.iam.flow.shared.application.configuration.valueprovider.RoleProviderConfig;
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.PluginListProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

@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 it is covered by a matching role.</p>",
   displayName = "Role-based OAuth 2.0 Scope Condition"
)
@PluginLicenseRestriction(moduleAffiliation = "OAuthServer")
public class RoleBasedOAuth2ScopeConditionConfig 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";
   @PluginListProperty(description = "Plugin to determine the roles to match the scope against.", optional = false)
   private List<RoleProviderConfig> roleProvider;

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

   public List<RoleProviderConfig> getRoleProvider() {
      return this.roleProvider;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public RoleBasedOAuth2ScopeConditionConfig(OAuth2ScopeMatcherConfig scopeMatcher, List<RoleProviderConfig> roleProvider) {
      this.scopeMatcher = scopeMatcher;
      this.roleProvider = roleProvider;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RoleBasedOAuth2ScopeConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ScopeMatcherConfig scopeMatcher;
      @SuppressFBWarnings(justification = "generated code")
      private List<RoleProviderConfig> roleProvider;

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

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

      @SuppressFBWarnings(justification = "generated code")
      public RoleBasedOAuth2ScopeConditionConfig.RoleBasedOAuth2ScopeConditionConfigBuilder roleProvider(List<RoleProviderConfig> roleProvider) {
         this.roleProvider = roleProvider;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RoleBasedOAuth2ScopeConditionConfig.RoleBasedOAuth2ScopeConditionConfigBuilder(scopeMatcher="
            + this.scopeMatcher
            + ", roleProvider="
            + this.roleProvider
            + ")";
      }
   }
}
