package com.airlock.iam.oauth2.application.configuration.claims.conditions;

import com.airlock.iam.oauth2.api.application.configuration.claims.ClaimConditionConfig;
import com.airlock.iam.oauth2.api.domain.model.OAuth2Scope;
import com.airlock.iam.oauth2.api.domain.model.claims.conditions.ClaimCondition;
import com.airlock.iam.oauth2.domain.model.claims.conditions.RequiredScopesClaimCondition;
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.StringListProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

@Plugin(description = "This condition is fulfilled if all of the configured scopes are present.")
@PluginLicenseRestriction(moduleAffiliation = "OAuthServer")
public final class RequiredScopesClaimConditionConfig implements ClaimConditionConfig {
   @StringListProperty(
      description = "This condition is fulfilled if every one of the following scopes is present.",
      validationRegex = "[\\x21\\x23-\\x5B\\x5D-\\x7E]+",
      minElements = 1,
      optional = false
   )
   private List<String> scopes;

   @Override
   public ClaimCondition logic() {
      return new RequiredScopesClaimCondition(OAuth2Scope.convertToScopes(this.scopes));
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public RequiredScopesClaimConditionConfig(List<String> scopes) {
      this.scopes = scopes;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RequiredScopesClaimConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private List<String> scopes;

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

      @SuppressFBWarnings(justification = "generated code")
      public RequiredScopesClaimConditionConfig.RequiredScopesClaimConditionConfigBuilder scopes(List<String> scopes) {
         this.scopes = scopes;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RequiredScopesClaimConditionConfig build() {
         return new RequiredScopesClaimConditionConfig(this.scopes);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RequiredScopesClaimConditionConfig.RequiredScopesClaimConditionConfigBuilder(scopes=" + this.scopes + ")";
      }
   }
}
