package com.airlock.iam.flow.shared.application.configuration.condition;

import com.airlock.iam.common.api.application.configuration.valueprovider.StringValueProviderConfig;
import com.airlock.iam.core.application.configuration.contextdata.ContextDataItemNameConfig;
import com.airlock.iam.flow.api.application.configuration.selection.FlowConditionConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "Condition that is fulfilled if the current user is the only one with the configured context-data value.",
   displayName = "User Attribute Is Unique"
)
public class UserAttributeUniquenessConditionConfig implements FlowConditionConfig {
   @PluginProperty(description = "The user attribute that is verified for uniqueness.", optional = false)
   private ContextDataItemNameConfig userAttribute;
   @PluginProperty(description = "The value of the user attribute that is verified for uniqueness.", optional = false)
   private StringValueProviderConfig attributeValueProvider;

   public ContextDataItemNameConfig getUserAttribute() {
      return this.userAttribute;
   }

   public StringValueProviderConfig getAttributeValueProvider() {
      return this.attributeValueProvider;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public UserAttributeUniquenessConditionConfig(ContextDataItemNameConfig userAttribute, StringValueProviderConfig attributeValueProvider) {
      this.userAttribute = userAttribute;
      this.attributeValueProvider = attributeValueProvider;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class UserAttributeUniquenessConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private ContextDataItemNameConfig userAttribute;
      @SuppressFBWarnings(justification = "generated code")
      private StringValueProviderConfig attributeValueProvider;

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

      @SuppressFBWarnings(justification = "generated code")
      public UserAttributeUniquenessConditionConfig.UserAttributeUniquenessConditionConfigBuilder userAttribute(ContextDataItemNameConfig userAttribute) {
         this.userAttribute = userAttribute;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserAttributeUniquenessConditionConfig.UserAttributeUniquenessConditionConfigBuilder attributeValueProvider(
         StringValueProviderConfig attributeValueProvider
      ) {
         this.attributeValueProvider = attributeValueProvider;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserAttributeUniquenessConditionConfig build() {
         return new UserAttributeUniquenessConditionConfig(this.userAttribute, this.attributeValueProvider);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "UserAttributeUniquenessConditionConfig.UserAttributeUniquenessConditionConfigBuilder(userAttribute="
            + this.userAttribute
            + ", attributeValueProvider="
            + this.attributeValueProvider
            + ")";
      }
   }
}
