package com.airlock.iam.oauth2.domain.model.clientauthentication;

import com.airlock.iam.oauth2.api.domain.model.clientauthentication.OAuth2AuthClientId;
import com.airlock.iam.oauth2.api.domain.model.clientauthentication.OAuth2ClientAuthenticationPayload;
import com.airlock.iam.oauth2.api.domain.model.clientauthentication.OAuth2ClientAuthenticationVerificationMethod;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import lombok.NonNull;

public final class OAuth2ClientSecretAuthenticationPayload implements OAuth2ClientAuthenticationPayload {
   @NonNull
   private final OAuth2AuthClientId clientId;
   @NonNull
   private final Optional<String> clientIdFromRequest;
   @NonNull
   private final String secret;
   @NonNull
   private final OAuth2ClientAuthenticationVerificationMethod method;

   @Override
   public Optional<OAuth2AuthClientId> clientId() {
      return Optional.of(this.clientId);
   }

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

   @SuppressFBWarnings(justification = "generated code")
   private OAuth2ClientSecretAuthenticationPayload(
      @NonNull OAuth2AuthClientId clientId,
      @NonNull Optional<String> clientIdFromRequest,
      @NonNull String secret,
      @NonNull OAuth2ClientAuthenticationVerificationMethod method
   ) {
      if (clientId == null) {
         throw new NullPointerException("clientId is marked non-null but is null");
      }

      if (clientIdFromRequest == null) {
         throw new NullPointerException("clientIdFromRequest is marked non-null but is null");
      }

      if (secret == null) {
         throw new NullPointerException("secret is marked non-null but is null");
      }

      if (method == null) {
         throw new NullPointerException("method is marked non-null but is null");
      }

      this.clientId = clientId;
      this.clientIdFromRequest = clientIdFromRequest;
      this.secret = secret;
      this.method = method;
   }

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

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Optional<String> clientIdFromRequest() {
      return this.clientIdFromRequest;
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   @Override
   public OAuth2ClientAuthenticationVerificationMethod method() {
      return this.method;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class OAuth2ClientSecretAuthenticationPayloadBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2AuthClientId clientId;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<String> clientIdFromRequest;
      @SuppressFBWarnings(justification = "generated code")
      private String secret;
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ClientAuthenticationVerificationMethod method;

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

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2ClientSecretAuthenticationPayload.OAuth2ClientSecretAuthenticationPayloadBuilder clientId(@NonNull OAuth2AuthClientId clientId) {
         if (clientId == null) {
            throw new NullPointerException("clientId is marked non-null but is null");
         }

         this.clientId = clientId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2ClientSecretAuthenticationPayload.OAuth2ClientSecretAuthenticationPayloadBuilder clientIdFromRequest(
         @NonNull Optional<String> clientIdFromRequest
      ) {
         if (clientIdFromRequest == null) {
            throw new NullPointerException("clientIdFromRequest is marked non-null but is null");
         }

         this.clientIdFromRequest = clientIdFromRequest;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2ClientSecretAuthenticationPayload.OAuth2ClientSecretAuthenticationPayloadBuilder secret(@NonNull String secret) {
         if (secret == null) {
            throw new NullPointerException("secret is marked non-null but is null");
         }

         this.secret = secret;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2ClientSecretAuthenticationPayload.OAuth2ClientSecretAuthenticationPayloadBuilder method(
         @NonNull OAuth2ClientAuthenticationVerificationMethod method
      ) {
         if (method == null) {
            throw new NullPointerException("method is marked non-null but is null");
         }

         this.method = method;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2ClientSecretAuthenticationPayload build() {
         return new OAuth2ClientSecretAuthenticationPayload(this.clientId, this.clientIdFromRequest, this.secret, this.method);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "OAuth2ClientSecretAuthenticationPayload.OAuth2ClientSecretAuthenticationPayloadBuilder(clientId="
            + this.clientId
            + ", clientIdFromRequest="
            + this.clientIdFromRequest
            + ", secret="
            + this.secret
            + ", method="
            + this.method
            + ")";
      }
   }
}
