package com.airlock.iam.oauth2.application.service.introspection;

import com.airlock.iam.oauth2.domain.model.token.OAuth2TokenBinding;
import com.google.common.collect.ImmutableSet;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import java.util.Set;

public final class TokenIntrospectionResult {
   private final boolean active;
   private final String clientId;
   private final String subject;
   private final Set<String> scopes;
   private final Optional<Long> expiryDate;
   private final long generationDate;
   private final Optional<OAuth2TokenBinding> tokenBinding;

   private TokenIntrospectionResult() {
      this.active = false;
      this.clientId = null;
      this.subject = null;
      this.scopes = ImmutableSet.of();
      this.expiryDate = Optional.empty();
      this.generationDate = 0L;
      this.tokenBinding = Optional.empty();
   }

   private TokenIntrospectionResult(String clientId, String subject, Set<String> scopes, long generationDate, Long expiryDate, OAuth2TokenBinding tokenBinding) {
      this.active = true;
      this.generationDate = generationDate;
      this.expiryDate = Optional.ofNullable(expiryDate);
      this.clientId = clientId;
      this.subject = subject;
      this.scopes = asImmutableSet(scopes);
      this.tokenBinding = Optional.ofNullable(tokenBinding);
   }

   private static ImmutableSet<String> asImmutableSet(Set<String> scopes) {
      return scopes == null ? ImmutableSet.of() : ImmutableSet.copyOf(scopes);
   }

   @SuppressFBWarnings(justification = "generated code")
   public static TokenIntrospectionResult.InactiveTokenResultBuilder inactiveTokenResult() {
      return new TokenIntrospectionResult.InactiveTokenResultBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public static TokenIntrospectionResult.ActiveTokenResultBuilder activeTokenResult() {
      return new TokenIntrospectionResult.ActiveTokenResultBuilder();
   }

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public Set<String> getScopes() {
      return this.scopes;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Long> getExpiryDate() {
      return this.expiryDate;
   }

   @SuppressFBWarnings(justification = "generated code")
   public long getGenerationDate() {
      return this.generationDate;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<OAuth2TokenBinding> getTokenBinding() {
      return this.tokenBinding;
   }

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

         if (this.generationDate != other.generationDate) {
            return false;
         }

         Object this$clientId = this.clientId;
         Object other$clientId = other.clientId;
         if (this$clientId == null ? other$clientId == null : this$clientId.equals(other$clientId)) {
            Object this$subject = this.subject;
            Object other$subject = other.subject;
            if (this$subject == null ? other$subject == null : this$subject.equals(other$subject)) {
               Object this$scopes = this.scopes;
               Object other$scopes = other.scopes;
               if (this$scopes == null ? other$scopes == null : this$scopes.equals(other$scopes)) {
                  Object this$expiryDate = this.expiryDate;
                  Object other$expiryDate = other.expiryDate;
                  if (this$expiryDate == null ? other$expiryDate == null : this$expiryDate.equals(other$expiryDate)) {
                     Object this$tokenBinding = this.tokenBinding;
                     Object other$tokenBinding = other.tokenBinding;
                     return this$tokenBinding == null ? other$tokenBinding == null : this$tokenBinding.equals(other$tokenBinding);
                  } else {
                     return false;
                  }
               } else {
                  return false;
               }
            } else {
               return false;
            }
         } else {
            return false;
         }
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      result = result * 59 + (this.active ? 79 : 97);
      long $generationDate = this.generationDate;
      result = result * 59 + (int)($generationDate >>> 32 ^ $generationDate);
      Object $clientId = this.clientId;
      result = result * 59 + ($clientId == null ? 43 : $clientId.hashCode());
      Object $subject = this.subject;
      result = result * 59 + ($subject == null ? 43 : $subject.hashCode());
      Object $scopes = this.scopes;
      result = result * 59 + ($scopes == null ? 43 : $scopes.hashCode());
      Object $expiryDate = this.expiryDate;
      result = result * 59 + ($expiryDate == null ? 43 : $expiryDate.hashCode());
      Object $tokenBinding = this.tokenBinding;
      return result * 59 + ($tokenBinding == null ? 43 : $tokenBinding.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "TokenIntrospectionResult(active="
         + this.isActive()
         + ", clientId="
         + this.getClientId()
         + ", subject="
         + this.getSubject()
         + ", scopes="
         + this.getScopes()
         + ", expiryDate="
         + this.getExpiryDate()
         + ", generationDate="
         + this.getGenerationDate()
         + ", tokenBinding="
         + this.getTokenBinding()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class ActiveTokenResultBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String clientId;
      @SuppressFBWarnings(justification = "generated code")
      private String subject;
      @SuppressFBWarnings(justification = "generated code")
      private Set<String> scopes;
      @SuppressFBWarnings(justification = "generated code")
      private long generationDate;
      @SuppressFBWarnings(justification = "generated code")
      private Long expiryDate;
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2TokenBinding tokenBinding;

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

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult.ActiveTokenResultBuilder clientId(String clientId) {
         this.clientId = clientId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult.ActiveTokenResultBuilder subject(String subject) {
         this.subject = subject;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult.ActiveTokenResultBuilder scopes(Set<String> scopes) {
         this.scopes = scopes;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult.ActiveTokenResultBuilder generationDate(long generationDate) {
         this.generationDate = generationDate;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult.ActiveTokenResultBuilder expiryDate(Long expiryDate) {
         this.expiryDate = expiryDate;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult.ActiveTokenResultBuilder tokenBinding(OAuth2TokenBinding tokenBinding) {
         this.tokenBinding = tokenBinding;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult build() {
         return new TokenIntrospectionResult(this.clientId, this.subject, this.scopes, this.generationDate, this.expiryDate, this.tokenBinding);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "TokenIntrospectionResult.ActiveTokenResultBuilder(clientId="
            + this.clientId
            + ", subject="
            + this.subject
            + ", scopes="
            + this.scopes
            + ", generationDate="
            + this.generationDate
            + ", expiryDate="
            + this.expiryDate
            + ", tokenBinding="
            + this.tokenBinding
            + ")";
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class InactiveTokenResultBuilder {
      @SuppressFBWarnings(justification = "generated code")
      InactiveTokenResultBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public TokenIntrospectionResult build() {
         return new TokenIntrospectionResult();
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "TokenIntrospectionResult.InactiveTokenResultBuilder()";
      }
   }
}
