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

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

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

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

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

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

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

   @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 getTimeOffset() {
      return this.timeOffset;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof TotpToken other)) {
         return false;
      } else {
         if (this.timeOffset != other.timeOffset) {
            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 $timeOffset = this.timeOffset;
      result = result * 59 + (int)($timeOffset >>> 32 ^ $timeOffset);
      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 "TotpToken(userId="
         + this.getUserId()
         + ", sharedSecret="
         + this.getSharedSecret()
         + ", organizationLabel="
         + this.getOrganizationLabel()
         + ", timeOffset="
         + this.getTimeOffset()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class TotpTokenBuilder {
      @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 timeOffset;

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public TotpToken.TotpTokenBuilder timeOffset(long timeOffset) {
         this.timeOffset = timeOffset;
         return this;
      }

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

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