package com.airlock.iam.apipolicyservice.domain.model;

import com.airlock.iam.techclient.domain.model.apikey.ApiKeySecret;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Instant;

public final class ApiPolicyServiceApiKey {
   private final ApiKeySecret secret;
   private final Instant validFrom;
   private final Instant validTo;
   private final boolean locked;

   public boolean isValid() {
      Instant now = Instant.now();
      return (this.validFrom == null || now.isAfter(this.validFrom)) && (this.validTo == null || now.isBefore(this.validTo));
   }

   @SuppressFBWarnings(justification = "generated code")
   ApiPolicyServiceApiKey(ApiKeySecret secret, Instant validFrom, Instant validTo, boolean locked) {
      this.secret = secret;
      this.validFrom = validFrom;
      this.validTo = validTo;
      this.locked = locked;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static ApiPolicyServiceApiKey.ApiPolicyServiceApiKeyBuilder builder() {
      return new ApiPolicyServiceApiKey.ApiPolicyServiceApiKeyBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public ApiKeySecret getSecret() {
      return this.secret;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public boolean isLocked() {
      return this.locked;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof ApiPolicyServiceApiKey other)) {
         return false;
      } else {
         if (this.locked != other.locked) {
            return false;
         }

         Object this$secret = this.secret;
         Object other$secret = other.secret;
         if (this$secret == null ? other$secret == null : this$secret.equals(other$secret)) {
            Object this$validFrom = this.validFrom;
            Object other$validFrom = other.validFrom;
            if (this$validFrom == null ? other$validFrom == null : this$validFrom.equals(other$validFrom)) {
               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;
      result = result * 59 + (this.locked ? 79 : 97);
      Object $secret = this.secret;
      result = result * 59 + ($secret == null ? 43 : $secret.hashCode());
      Object $validFrom = this.validFrom;
      result = result * 59 + ($validFrom == null ? 43 : $validFrom.hashCode());
      Object $validTo = this.validTo;
      return result * 59 + ($validTo == null ? 43 : $validTo.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "ApiPolicyServiceApiKey(secret="
         + this.getSecret()
         + ", validFrom="
         + this.getValidFrom()
         + ", validTo="
         + this.getValidTo()
         + ", locked="
         + this.isLocked()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class ApiPolicyServiceApiKeyBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private ApiKeySecret secret;
      @SuppressFBWarnings(justification = "generated code")
      private Instant validFrom;
      @SuppressFBWarnings(justification = "generated code")
      private Instant validTo;
      @SuppressFBWarnings(justification = "generated code")
      private boolean locked;

      @SuppressFBWarnings(justification = "generated code")
      ApiPolicyServiceApiKeyBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public ApiPolicyServiceApiKey.ApiPolicyServiceApiKeyBuilder secret(ApiKeySecret secret) {
         this.secret = secret;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public ApiPolicyServiceApiKey.ApiPolicyServiceApiKeyBuilder validFrom(Instant validFrom) {
         this.validFrom = validFrom;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      public ApiPolicyServiceApiKey.ApiPolicyServiceApiKeyBuilder locked(boolean locked) {
         this.locked = locked;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public ApiPolicyServiceApiKey build() {
         return new ApiPolicyServiceApiKey(this.secret, this.validFrom, this.validTo, this.locked);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "ApiPolicyServiceApiKey.ApiPolicyServiceApiKeyBuilder(secret="
            + this.secret
            + ", validFrom="
            + this.validFrom
            + ", validTo="
            + this.validTo
            + ", locked="
            + this.locked
            + ")";
      }
   }
}
