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

import com.airlock.iam.core.misc.util.oathotp.OathOtpUtilities;
import java.util.Optional;

public interface OathOtpToken {
   String getUserId();

   Optional<byte[]> getSharedSecret();

   String getOrganizationLabel();

   long getVerificationInformation();

   default Optional<String> getSecretBase32() {
      return this.getSharedSecret().isPresent() ? Optional.of(OathOtpUtilities.encodeBase32ForGoogleAuthenticator(this.getSharedSecret())) : Optional.empty();
   }

   default Optional<String> getSecretHex() {
      return this.getSharedSecret().isPresent() ? Optional.of(OathOtpUtilities.encodeToHex(this.getSharedSecret().get())) : Optional.empty();
   }

   static OathOtpToken of(String userId, Optional<byte[]> sharedSecret, String organizationLabel, long verificationInformation, boolean isTimeBased) {
      return isTimeBased
         ? TotpToken.of(userId, sharedSecret, organizationLabel, verificationInformation)
         : HotpToken.of(userId, sharedSecret, organizationLabel, verificationInformation);
   }
}
