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 performing an age check. The specified age in years is compared to the threshold value (also in years) using the selected relation.<br>\nExample: To check if someone is over 18, set the attribute name to e.g. <q>birthdate_dateint</q>\n (where the attribute contains a date in the format YYYYMMDD), the predicate type to <q>GREATER_EQ</q> and the age threshold to 18.",
   displayName = "SSI Age Check Predicate"
)
public final class AgePredicateConfig implements SsiPredicateConfig {
   @StringProperty(
      description = "The attribute checked by the predicate.",
      displayName = "Attribute name",
      exampleValues = {"birthDate", "bestBeforeDate", "employmentStartDate"},
      optional = false
   )
   private String name;
   @EnumProperty(description = "The type of the predicate.", displayName = "Predicate type", optional = false)
   private PredicateType type;
   @IntegerProperty(description = "An age expressed in years.", exampleValues = {18, 21, 65}, optional = false)
   private Integer ageThreshold;
   @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 getAgeThreshold() {
      return this.ageThreshold;
   }

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

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

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

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

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public AgePredicateConfig.AgePredicateConfigBuilder ageThreshold(Integer ageThreshold) {
         this.ageThreshold = ageThreshold;
         return this;
      }

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

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

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