package com.airlock.iam.flow.shared.domain.model.rememberme;

import com.airlock.iam.common.api.domain.model.binary.ByteSequence;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Objects;
import org.apache.commons.lang3.Validate;

public final class RememberMeSecretHash {
   private static final int NUMBER_OF_BYTES = 64;
   private final ByteSequence hash;

   private RememberMeSecretHash(byte[] bytes) {
      Objects.requireNonNull(bytes);
      Validate.isTrue(bytes.length == 64, String.format("Expected %d bytes, but got %d", 64, bytes.length), new Object[0]);
      this.hash = ByteSequence.byteSequence(bytes);
   }

   public static RememberMeSecretHash rememberMeTokenHash(byte[] bytes) {
      return new RememberMeSecretHash(bytes);
   }

   public String base64Url() {
      return this.hash.base64Url();
   }

   public byte[] bytes() {
      return this.hash.bytes();
   }

   @Override
   public String toString() {
      return this.hash.toString();
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof RememberMeSecretHash other)) {
         return false;
      } else {
         Object this$hash = this.hash;
         Object other$hash = other.hash;
         return this$hash == null ? other$hash == null : this$hash.equals(other$hash);
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $hash = this.hash;
      return result * 59 + ($hash == null ? 43 : $hash.hashCode());
   }
}
