package com.airlock.iam.admin.domain.model.certificate;

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

public final class CertificateValidity {
   private final Optional<Date> notBefore;
   private final Optional<Date> notAfter;

   public boolean isValid() {
      Date now = new Date();
      return this.notBefore.isPresent() && now.before(this.notBefore.get()) ? false : this.notAfter.isEmpty() || !now.after(this.notAfter.get());
   }

   @SuppressFBWarnings(justification = "generated code")
   public CertificateValidity(Optional<Date> notBefore, Optional<Date> notAfter) {
      this.notBefore = notBefore;
      this.notAfter = notAfter;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Date> getNotBefore() {
      return this.notBefore;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Date> getNotAfter() {
      return this.notAfter;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "CertificateValidity(notBefore=" + this.getNotBefore() + ", notAfter=" + this.getNotAfter() + ")";
   }
}
