package com.airlock.iam.oauth2.api.domain.model.tokenexchange;

import com.airlock.iam.oauth2.api.domain.model.OAuth2ClientId;
import com.airlock.iam.oauth2.api.domain.model.OAuth2Scope;
import com.airlock.iam.oauth2.api.domain.model.clientauthentication.OAuth2ClientAuthenticationPayload;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import lombok.NonNull;

public final class OAuth2TokenExchangeGrantRequest {
   @NonNull
   private final OAuth2ClientId clientId;
   @NonNull
   private final Optional<OAuth2ClientAuthenticationPayload> authenticationPayload;
   @NonNull
   private final List<OAuth2TokenExchangeTargetResource> resource;
   @NonNull
   private final List<OAuth2TokenExchangeTargetAudience> audience;
   @NonNull
   private final Set<OAuth2Scope> scope;
   @NonNull
   private final Optional<OAuth2TokenExchangeTokenType> requestedTokenType;
   @NonNull
   private final OAuth2TokenExchangeRawToken subjectToken;
   @NonNull
   private final Optional<OAuth2TokenExchangeRawToken> actorToken;
   @NonNull
   private final Map<String, List<String>> customParameters;

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

   @SuppressFBWarnings(justification = "generated code")
   public OAuth2TokenExchangeGrantRequest(
      @NonNull OAuth2ClientId clientId,
      @NonNull Optional<OAuth2ClientAuthenticationPayload> authenticationPayload,
      @NonNull List<OAuth2TokenExchangeTargetResource> resource,
      @NonNull List<OAuth2TokenExchangeTargetAudience> audience,
      @NonNull Set<OAuth2Scope> scope,
      @NonNull Optional<OAuth2TokenExchangeTokenType> requestedTokenType,
      @NonNull OAuth2TokenExchangeRawToken subjectToken,
      @NonNull Optional<OAuth2TokenExchangeRawToken> actorToken,
      @NonNull Map<String, List<String>> customParameters
   ) {
      if (clientId == null) {
         throw new NullPointerException("clientId is marked non-null but is null");
      }

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

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

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

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

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

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

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

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

      this.clientId = clientId;
      this.authenticationPayload = authenticationPayload;
      this.resource = resource;
      this.audience = audience;
      this.scope = scope;
      this.requestedTokenType = requestedTokenType;
      this.subjectToken = subjectToken;
      this.actorToken = actorToken;
      this.customParameters = customParameters;
   }

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

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public List<OAuth2TokenExchangeTargetResource> getResource() {
      return this.resource;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public List<OAuth2TokenExchangeTargetAudience> getAudience() {
      return this.audience;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Set<OAuth2Scope> getScope() {
      return this.scope;
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public OAuth2TokenExchangeRawToken getSubjectToken() {
      return this.subjectToken;
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Map<String, List<String>> getCustomParameters() {
      return this.customParameters;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class OAuth2TokenExchangeGrantRequestBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ClientId clientId;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<OAuth2ClientAuthenticationPayload> authenticationPayload;
      @SuppressFBWarnings(justification = "generated code")
      private List<OAuth2TokenExchangeTargetResource> resource;
      @SuppressFBWarnings(justification = "generated code")
      private List<OAuth2TokenExchangeTargetAudience> audience;
      @SuppressFBWarnings(justification = "generated code")
      private Set<OAuth2Scope> scope;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<OAuth2TokenExchangeTokenType> requestedTokenType;
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2TokenExchangeRawToken subjectToken;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<OAuth2TokenExchangeRawToken> actorToken;
      @SuppressFBWarnings(justification = "generated code")
      private Map<String, List<String>> customParameters;

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

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder clientId(@NonNull OAuth2ClientId 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 OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder authenticationPayload(
         @NonNull Optional<OAuth2ClientAuthenticationPayload> authenticationPayload
      ) {
         if (authenticationPayload == null) {
            throw new NullPointerException("authenticationPayload is marked non-null but is null");
         }

         this.authenticationPayload = authenticationPayload;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder resource(@NonNull List<OAuth2TokenExchangeTargetResource> resource) {
         if (resource == null) {
            throw new NullPointerException("resource is marked non-null but is null");
         }

         this.resource = resource;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder audience(@NonNull List<OAuth2TokenExchangeTargetAudience> audience) {
         if (audience == null) {
            throw new NullPointerException("audience is marked non-null but is null");
         }

         this.audience = audience;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder scope(@NonNull Set<OAuth2Scope> scope) {
         if (scope == null) {
            throw new NullPointerException("scope is marked non-null but is null");
         }

         this.scope = scope;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder requestedTokenType(
         @NonNull Optional<OAuth2TokenExchangeTokenType> requestedTokenType
      ) {
         if (requestedTokenType == null) {
            throw new NullPointerException("requestedTokenType is marked non-null but is null");
         }

         this.requestedTokenType = requestedTokenType;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder subjectToken(@NonNull OAuth2TokenExchangeRawToken subjectToken) {
         if (subjectToken == null) {
            throw new NullPointerException("subjectToken is marked non-null but is null");
         }

         this.subjectToken = subjectToken;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder actorToken(@NonNull Optional<OAuth2TokenExchangeRawToken> actorToken) {
         if (actorToken == null) {
            throw new NullPointerException("actorToken is marked non-null but is null");
         }

         this.actorToken = actorToken;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder customParameters(@NonNull Map<String, List<String>> customParameters) {
         if (customParameters == null) {
            throw new NullPointerException("customParameters is marked non-null but is null");
         }

         this.customParameters = customParameters;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantRequest build() {
         return new OAuth2TokenExchangeGrantRequest(
            this.clientId,
            this.authenticationPayload,
            this.resource,
            this.audience,
            this.scope,
            this.requestedTokenType,
            this.subjectToken,
            this.actorToken,
            this.customParameters
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "OAuth2TokenExchangeGrantRequest.OAuth2TokenExchangeGrantRequestBuilder(clientId="
            + this.clientId
            + ", authenticationPayload="
            + this.authenticationPayload
            + ", resource="
            + this.resource
            + ", audience="
            + this.audience
            + ", scope="
            + this.scope
            + ", requestedTokenType="
            + this.requestedTokenType
            + ", subjectToken="
            + this.subjectToken
            + ", actorToken="
            + this.actorToken
            + ", customParameters="
            + this.customParameters
            + ")";
      }
   }
}
