package com.airlock.iam.common.application.configuration.valueprovider;

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

@Plugin(description = "The first non-null value in the list of String Value Providers will be provided.", displayName = "Fallback String Value Provider")
public final class FallbackStringValueProviderConfig implements StringValueProviderConfig {
   @PluginListProperty(
      description = "A list of StringValueProviders which are evaluated. The first non-null value will be provided.",
      optional = false,
      minElements = 1
   )
   private List<StringValueProviderConfig> stringValueProviders;
   @BooleanProperty(description = "If activated, empty strings will be treated as null.", optional = true, defaultValue = "false")
   private boolean treatEmptyStringsAsNull;

   public List<StringValueProviderConfig> getStringValueProviders() {
      return this.stringValueProviders;
   }

   public boolean isTreatEmptyStringsAsNull() {
      return this.treatEmptyStringsAsNull;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public FallbackStringValueProviderConfig(List<StringValueProviderConfig> stringValueProviders, boolean treatEmptyStringsAsNull) {
      this.stringValueProviders = stringValueProviders;
      this.treatEmptyStringsAsNull = treatEmptyStringsAsNull;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class FallbackStringValueProviderConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private List<StringValueProviderConfig> stringValueProviders;
      @SuppressFBWarnings(justification = "generated code")
      private boolean treatEmptyStringsAsNull;

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

      @SuppressFBWarnings(justification = "generated code")
      public FallbackStringValueProviderConfig.FallbackStringValueProviderConfigBuilder stringValueProviders(
         List<StringValueProviderConfig> stringValueProviders
      ) {
         this.stringValueProviders = stringValueProviders;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public FallbackStringValueProviderConfig.FallbackStringValueProviderConfigBuilder treatEmptyStringsAsNull(boolean treatEmptyStringsAsNull) {
         this.treatEmptyStringsAsNull = treatEmptyStringsAsNull;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public FallbackStringValueProviderConfig build() {
         return new FallbackStringValueProviderConfig(this.stringValueProviders, this.treatEmptyStringsAsNull);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "FallbackStringValueProviderConfig.FallbackStringValueProviderConfigBuilder(stringValueProviders="
            + this.stringValueProviders
            + ", treatEmptyStringsAsNull="
            + this.treatEmptyStringsAsNull
            + ")";
      }
   }
}
