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

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Duration;
import java.time.Instant;

public final class DeviceTokenChallenge {
   private static final Duration VALIDITY = Duration.ofMinutes(10L);
   private final String deviceTokenId;
   private final String challenge;
   private final Instant validTo;

   public DeviceTokenChallenge(String deviceTokenId, String challenge) {
      this.deviceTokenId = deviceTokenId;
      this.challenge = challenge;
      this.validTo = Instant.now().plus(VALIDITY);
   }

   public DeviceTokenChallenge(String deviceTokenId, String challenge, Instant validTo) {
      this.deviceTokenId = deviceTokenId;
      this.challenge = challenge;
      this.validTo = validTo;
   }

   public boolean hasExpired() {
      return Instant.now().isAfter(this.validTo);
   }

   @SuppressFBWarnings(justification = "generated code")
   public String getDeviceTokenId() {
      return this.deviceTokenId;
   }

   @SuppressFBWarnings(justification = "generated code")
   public String getChallenge() {
      return this.challenge;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Instant getValidTo() {
      return this.validTo;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "DeviceTokenChallenge(deviceTokenId=" + this.getDeviceTokenId() + ", challenge=" + this.getChallenge() + ", validTo=" + this.getValidTo() + ")";
   }
}
