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

import com.airlock.iam.common.api.application.configuration.valueprovider.StringValueProviderConfig;
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.BooleanProperty;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.regex.Pattern;

@Plugin(description = "This condition is fulfilled if the regex pattern matches the value provided by the string value provider.")
public final class StringRegexConditionConfig implements FlowConditionConfig {
   @PluginProperty(
      description = "String value provider whose provided value the regex pattern is applied to decide whether the condition is fulfilled.",
      optional = false
   )
   private StringValueProviderConfig valueProvider;
   @RegexProperty(description = "If the regex pattern matches the value provided by the value provider, the condition is fulfilled.", optional = false)
   private Pattern regexPattern;
   @BooleanProperty(
      description = "If checked, the condition is fulfilled if the provided value is null. If unchecked, the condition is unfulfilled in that situation.",
      optional = true,
      defaultValue = "false"
   )
   private boolean isFulfilledIfValueIsNull;

   public StringValueProviderConfig getValueProvider() {
      return this.valueProvider;
   }

   public Pattern getRegexPattern() {
      return this.regexPattern;
   }

   public boolean isFulfilledIfValueIsNull() {
      return this.isFulfilledIfValueIsNull;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public StringRegexConditionConfig(StringValueProviderConfig valueProvider, Pattern regexPattern, boolean isFulfilledIfValueIsNull) {
      this.valueProvider = valueProvider;
      this.regexPattern = regexPattern;
      this.isFulfilledIfValueIsNull = isFulfilledIfValueIsNull;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class StringRegexConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private StringValueProviderConfig valueProvider;
      @SuppressFBWarnings(justification = "generated code")
      private Pattern regexPattern;
      @SuppressFBWarnings(justification = "generated code")
      private boolean isFulfilledIfValueIsNull;

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

      @SuppressFBWarnings(justification = "generated code")
      public StringRegexConditionConfig.StringRegexConditionConfigBuilder valueProvider(StringValueProviderConfig valueProvider) {
         this.valueProvider = valueProvider;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StringRegexConditionConfig.StringRegexConditionConfigBuilder regexPattern(Pattern regexPattern) {
         this.regexPattern = regexPattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StringRegexConditionConfig.StringRegexConditionConfigBuilder isFulfilledIfValueIsNull(boolean isFulfilledIfValueIsNull) {
         this.isFulfilledIfValueIsNull = isFulfilledIfValueIsNull;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StringRegexConditionConfig build() {
         return new StringRegexConditionConfig(this.valueProvider, this.regexPattern, this.isFulfilledIfValueIsNull);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "StringRegexConditionConfig.StringRegexConditionConfigBuilder(valueProvider="
            + this.valueProvider
            + ", regexPattern="
            + this.regexPattern
            + ", isFulfilledIfValueIsNull="
            + this.isFulfilledIfValueIsNull
            + ")";
      }
   }
}
