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

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.security.cert.X509Certificate;
import java.util.Optional;

public final class ClientTlsCertificate {
   @Nullable
   private final X509Certificate x509Certificate;
   @Nullable
   private final String failure;

   public static ClientTlsCertificate validClientTlsCertificate(@Nonnull X509Certificate x509Certificate) {
      return new ClientTlsCertificate(x509Certificate, null);
   }

   public static ClientTlsCertificate invalidClientTlsCertificate(@Nonnull String failure) {
      return new ClientTlsCertificate(null, failure);
   }

   public Optional<X509Certificate> getX509Certificate() {
      return Optional.ofNullable(this.x509Certificate);
   }

   public Optional<String> getFailure() {
      return Optional.ofNullable(this.failure);
   }

   @SuppressFBWarnings(justification = "generated code")
   private ClientTlsCertificate(@Nullable X509Certificate x509Certificate, @Nullable String failure) {
      this.x509Certificate = x509Certificate;
      this.failure = failure;
   }

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

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