package com.airlock.iam.common.domain.model.otp;

import com.airlock.iam.common.api.domain.model.otp.OneTimePassword;
import com.airlock.iam.common.api.domain.model.otp.Otp;
import com.airlock.iam.common.api.domain.model.otp.OtpEqualityStrategy;
import com.airlock.iam.common.api.domain.model.otp.UnverifiedOtp;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public final class NonExpiringOneTimePassword implements OneTimePassword {
   private final Otp value;

   public static NonExpiringOneTimePassword nonExpiringOneTimeCode(Otp value) {
      return new NonExpiringOneTimePassword(value);
   }

   @Override
   public OneTimePassword.OneTimeCodeVerificationResult verify(UnverifiedOtp otherValue, OtpEqualityStrategy strategy) {
      return strategy.equals(this.value, otherValue)
         ? OneTimePassword.OneTimeCodeVerificationResult.SUCCESS
         : OneTimePassword.OneTimeCodeVerificationResult.WRONG_VALUE;
   }

   public NonExpiringOneTimePassword renewValidity() {
      return new NonExpiringOneTimePassword(this.value);
   }

   @Override
   public Otp value() {
      return this.value;
   }

   @SuppressFBWarnings(justification = "generated code")
   NonExpiringOneTimePassword(Otp value) {
      this.value = value;
   }

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

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