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

import com.airlock.iam.common.api.application.configuration.valueprovider.BooleanValueProviderConfig;
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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "This condition is fulfilled if the configured boolean value provider provides the value <code>true</code>.")
public class BooleanConditionConfig implements FlowConditionConfig {
   @PluginProperty(description = "Boolean value provider whose provided value will be used to determine whether the condition is fulfilled.", optional = false)
   private BooleanValueProviderConfig valueProvider;
   @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 BooleanValueProviderConfig getValueProvider() {
      return this.valueProvider;
   }

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public BooleanConditionConfig(BooleanValueProviderConfig valueProvider, boolean isFulfilledIfValueIsNull) {
      this.valueProvider = valueProvider;
      this.isFulfilledIfValueIsNull = isFulfilledIfValueIsNull;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class BooleanConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private BooleanValueProviderConfig valueProvider;
      @SuppressFBWarnings(justification = "generated code")
      private boolean isFulfilledIfValueIsNull;

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

      @SuppressFBWarnings(justification = "generated code")
      public BooleanConditionConfig.BooleanConditionConfigBuilder valueProvider(BooleanValueProviderConfig valueProvider) {
         this.valueProvider = valueProvider;
         return this;
      }

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

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

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