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

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.IntegerProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "Settings for masking a string value.", displayName = "Masking Settings")
public final class StringMaskingConfig implements MaskingConfig {
   @IntegerProperty(
      description = "The number of visible characters at the start of the string.<p>Note that if the length of the string is shorter or equal to the number of visible characters at the start and end, the string is not masked.</p>",
      minValue = 0,
      defaultValue = 3,
      optional = true
   )
   private int visibleStart;
   @IntegerProperty(
      description = "The number of visible characters at the end of the string.<p>Note that if the length of the string is shorter or equal to the number of visible characters at the start and end, the string is not masked.</p>",
      minValue = 0,
      defaultValue = 5,
      optional = true
   )
   private int visibleEnd;
   @StringProperty(description = "The character used for masking.", maxLength = 1, defaultValue = "*", exampleValues = {"*", "#"}, optional = true)
   private String maskingCharacter;

   public int getVisibleStart() {
      return this.visibleStart;
   }

   public int getVisibleEnd() {
      return this.visibleEnd;
   }

   public String getMaskingCharacter() {
      return this.maskingCharacter;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public StringMaskingConfig(int visibleStart, int visibleEnd, String maskingCharacter) {
      this.visibleStart = visibleStart;
      this.visibleEnd = visibleEnd;
      this.maskingCharacter = maskingCharacter;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class StringMaskingConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private int visibleStart;
      @SuppressFBWarnings(justification = "generated code")
      private int visibleEnd;
      @SuppressFBWarnings(justification = "generated code")
      private String maskingCharacter;

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

      @SuppressFBWarnings(justification = "generated code")
      public StringMaskingConfig.StringMaskingConfigBuilder visibleStart(int visibleStart) {
         this.visibleStart = visibleStart;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StringMaskingConfig.StringMaskingConfigBuilder visibleEnd(int visibleEnd) {
         this.visibleEnd = visibleEnd;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StringMaskingConfig.StringMaskingConfigBuilder maskingCharacter(String maskingCharacter) {
         this.maskingCharacter = maskingCharacter;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public StringMaskingConfig build() {
         return new StringMaskingConfig(this.visibleStart, this.visibleEnd, this.maskingCharacter);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "StringMaskingConfig.StringMaskingConfigBuilder(visibleStart="
            + this.visibleStart
            + ", visibleEnd="
            + this.visibleEnd
            + ", maskingCharacter="
            + this.maskingCharacter
            + ")";
      }
   }
}
