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

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.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "Key-value pair to be added to the ticket.")
public final class TicketKeyValue {
   @StringProperty(
      description = "The key of the ticket element. This is the key under which the key-value pair is added to the ticket.",
      exampleValues = {"username", "email"},
      optional = false
   )
   private String ticketKey;
   @StringProperty(
      description = "This selects an entry from the \"Value Providers\" to obtain the value for this key-value pair.",
      exampleValues = {"user-id", "email"},
      optional = false
   )
   private String valueSelector;
   @BooleanProperty(
      description = "If enabled and the obtained value is empty, this key-value pair is omitted from the ticket. A value is considered empty, if it is not provided or is null or the empty string.",
      optional = true,
      defaultValue = "false"
   )
   private boolean omitIfEmpty;

   public String getTicketKey() {
      return this.ticketKey;
   }

   public String getValueSelector() {
      return this.valueSelector;
   }

   public boolean isOmitIfEmpty() {
      return this.omitIfEmpty;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public TicketKeyValue(String ticketKey, String valueSelector, boolean omitIfEmpty) {
      this.ticketKey = ticketKey;
      this.valueSelector = valueSelector;
      this.omitIfEmpty = omitIfEmpty;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class TicketKeyValueBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String ticketKey;
      @SuppressFBWarnings(justification = "generated code")
      private String valueSelector;
      @SuppressFBWarnings(justification = "generated code")
      private boolean omitIfEmpty;

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

      @SuppressFBWarnings(justification = "generated code")
      public TicketKeyValue.TicketKeyValueBuilder ticketKey(String ticketKey) {
         this.ticketKey = ticketKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TicketKeyValue.TicketKeyValueBuilder valueSelector(String valueSelector) {
         this.valueSelector = valueSelector;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TicketKeyValue.TicketKeyValueBuilder omitIfEmpty(boolean omitIfEmpty) {
         this.omitIfEmpty = omitIfEmpty;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TicketKeyValue build() {
         return new TicketKeyValue(this.ticketKey, this.valueSelector, this.omitIfEmpty);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "TicketKeyValue.TicketKeyValueBuilder(ticketKey="
            + this.ticketKey
            + ", valueSelector="
            + this.valueSelector
            + ", omitIfEmpty="
            + this.omitIfEmpty
            + ")";
      }
   }
}
