package com.airlock.iam.ssi.application.configuration;

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.EnumProperty;
import com.airlock.iam.plugin.api.annotation.property.IntegerProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import com.airlock.iam.ssi.domain.model.step.PredicateType;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "A predicate for checking integer-valued attributes of a verifiable credential.<br>The threshold value is compared to the value of the attribute using the specified relation.",
   displayName = "Generic SSI Proof Predicate"
)
public final class GenericPredicateConfig implements SsiPredicateConfig {
   @StringProperty(
      description = "The attribute checked by the predicate.",
      displayName = "Attribute name",
      exampleValues = {"birthDate", "tenureYears", "subscriptionLevel"},
      optional = false
   )
   private String name;
   @EnumProperty(description = "The type of the predicate.", displayName = "Predicate type", optional = false)
   private PredicateType type;
   @IntegerProperty(description = "The threshold value.", exampleValues = {20030223, 21, 65}, optional = false)
   private Integer thresholdValue;
   @StringProperty(
      description = "The key which can be used for obtaining information on the verified predicate from the SSI Verification Data Provider.",
      exampleValues = "over18",
      optional = false
   )
   private String providerKey;

   public String getName() {
      return this.name;
   }

   public PredicateType getType() {
      return this.type;
   }

   public Integer getThresholdValue() {
      return this.thresholdValue;
   }

   public String getProviderKey() {
      return this.providerKey;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public GenericPredicateConfig(String name, PredicateType type, Integer thresholdValue, String providerKey) {
      this.name = name;
      this.type = type;
      this.thresholdValue = thresholdValue;
      this.providerKey = providerKey;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class GenericPredicateConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String name;
      @SuppressFBWarnings(justification = "generated code")
      private PredicateType type;
      @SuppressFBWarnings(justification = "generated code")
      private Integer thresholdValue;
      @SuppressFBWarnings(justification = "generated code")
      private String providerKey;

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

      @SuppressFBWarnings(justification = "generated code")
      public GenericPredicateConfig.GenericPredicateConfigBuilder name(String name) {
         this.name = name;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericPredicateConfig.GenericPredicateConfigBuilder type(PredicateType type) {
         this.type = type;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericPredicateConfig.GenericPredicateConfigBuilder thresholdValue(Integer thresholdValue) {
         this.thresholdValue = thresholdValue;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericPredicateConfig.GenericPredicateConfigBuilder providerKey(String providerKey) {
         this.providerKey = providerKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public GenericPredicateConfig build() {
         return new GenericPredicateConfig(this.name, this.type, this.thresholdValue, this.providerKey);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "GenericPredicateConfig.GenericPredicateConfigBuilder(name="
            + this.name
            + ", type="
            + this.type
            + ", thresholdValue="
            + this.thresholdValue
            + ", providerKey="
            + this.providerKey
            + ")";
      }
   }
}
