package com.airlock.iam.common.domain.model.token.oathotp;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;

public final class HotpToken implements OathOtpToken {
   private final String userId;
   private final Optional<byte[]> sharedSecret;
   private final String organizationLabel;
   private final long eventCounter;

   @Override
   public long getVerificationInformation() {
      return this.getEventCounter();
   }

   public static HotpToken of(String userId, Optional<byte[]> sharedSecret, String organizationLabel, long verificationInformation) {
      return builder().userId(userId).sharedSecret(sharedSecret).organizationLabel(organizationLabel).eventCounter(verificationInformation).build();
   }

   @SuppressFBWarnings(justification = "generated code")
   HotpToken(String userId, Optional<byte[]> sharedSecret, String organizationLabel, long eventCounter) {
      this.userId = userId;
      this.sharedSecret = sharedSecret;
      this.organizationLabel = organizationLabel;
      this.eventCounter = eventCounter;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String getUserId() {
      return this.userId;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public Optional<byte[]> getSharedSecret() {
      return this.sharedSecret;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String getOrganizationLabel() {
      return this.organizationLabel;
   }

   @SuppressFBWarnings(justification = "generated code")
   public long getEventCounter() {
      return this.eventCounter;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof HotpToken other)) {
         return false;
      } else {
         if (this.eventCounter != other.eventCounter) {
            return false;
         }

         Object this$userId = this.userId;
         Object other$userId = other.userId;
         if (this$userId == null ? other$userId == null : this$userId.equals(other$userId)) {
            Object this$sharedSecret = this.sharedSecret;
            Object other$sharedSecret = other.sharedSecret;
            if (this$sharedSecret == null ? other$sharedSecret == null : this$sharedSecret.equals(other$sharedSecret)) {
               Object this$organizationLabel = this.organizationLabel;
               Object other$organizationLabel = other.organizationLabel;
               return this$organizationLabel == null ? other$organizationLabel == null : this$organizationLabel.equals(other$organizationLabel);
            } else {
               return false;
            }
         } else {
            return false;
         }
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      long $eventCounter = this.eventCounter;
      result = result * 59 + (int)($eventCounter >>> 32 ^ $eventCounter);
      Object $userId = this.userId;
      result = result * 59 + ($userId == null ? 43 : $userId.hashCode());
      Object $sharedSecret = this.sharedSecret;
      result = result * 59 + ($sharedSecret == null ? 43 : $sharedSecret.hashCode());
      Object $organizationLabel = this.organizationLabel;
      return result * 59 + ($organizationLabel == null ? 43 : $organizationLabel.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "HotpToken(userId="
         + this.getUserId()
         + ", sharedSecret="
         + this.getSharedSecret()
         + ", organizationLabel="
         + this.getOrganizationLabel()
         + ", eventCounter="
         + this.getEventCounter()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class HotpTokenBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String userId;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<byte[]> sharedSecret;
      @SuppressFBWarnings(justification = "generated code")
      private String organizationLabel;
      @SuppressFBWarnings(justification = "generated code")
      private long eventCounter;

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

      @SuppressFBWarnings(justification = "generated code")
      public HotpToken.HotpTokenBuilder userId(String userId) {
         this.userId = userId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HotpToken.HotpTokenBuilder sharedSecret(Optional<byte[]> sharedSecret) {
         this.sharedSecret = sharedSecret;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HotpToken.HotpTokenBuilder organizationLabel(String organizationLabel) {
         this.organizationLabel = organizationLabel;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HotpToken.HotpTokenBuilder eventCounter(long eventCounter) {
         this.eventCounter = eventCounter;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public HotpToken build() {
         return new HotpToken(this.userId, this.sharedSecret, this.organizationLabel, this.eventCounter);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "HotpToken.HotpTokenBuilder(userId="
            + this.userId
            + ", sharedSecret="
            + this.sharedSecret
            + ", organizationLabel="
            + this.organizationLabel
            + ", eventCounter="
            + this.eventCounter
            + ")";
      }
   }
}
