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

import com.airlock.iam.oauth2.api.domain.model.OAuth2Scope;
import com.airlock.iam.oauth2.api.domain.model.tokenexchange.OAuth2TokenExchangeTokenType;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.Duration;
import java.util.Set;
import lombok.NonNull;

public final class OAuth2TokenExchangeGrantAccessToken {
   @NonNull
   private final OAuth2TokenExchangeTokenType issuedTokenType;
   @NonNull
   private final Duration tokenLifetime;
   @NonNull
   private final String accessToken;
   @NonNull
   private final Set<OAuth2Scope> scope;

   @SuppressFBWarnings(justification = "generated code")
   OAuth2TokenExchangeGrantAccessToken(
      @NonNull OAuth2TokenExchangeTokenType issuedTokenType, @NonNull Duration tokenLifetime, @NonNull String accessToken, @NonNull Set<OAuth2Scope> scope
   ) {
      if (issuedTokenType == null) {
         throw new NullPointerException("issuedTokenType is marked non-null but is null");
      }

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

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

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

      this.issuedTokenType = issuedTokenType;
      this.tokenLifetime = tokenLifetime;
      this.accessToken = accessToken;
      this.scope = scope;
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public OAuth2TokenExchangeTokenType getIssuedTokenType() {
      return this.issuedTokenType;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Duration getTokenLifetime() {
      return this.tokenLifetime;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class OAuth2TokenExchangeGrantAccessTokenBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2TokenExchangeTokenType issuedTokenType;
      @SuppressFBWarnings(justification = "generated code")
      private Duration tokenLifetime;
      @SuppressFBWarnings(justification = "generated code")
      private String accessToken;
      @SuppressFBWarnings(justification = "generated code")
      private Set<OAuth2Scope> scope;

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

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantAccessToken.OAuth2TokenExchangeGrantAccessTokenBuilder issuedTokenType(
         @NonNull OAuth2TokenExchangeTokenType issuedTokenType
      ) {
         if (issuedTokenType == null) {
            throw new NullPointerException("issuedTokenType is marked non-null but is null");
         }

         this.issuedTokenType = issuedTokenType;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantAccessToken.OAuth2TokenExchangeGrantAccessTokenBuilder tokenLifetime(@NonNull Duration tokenLifetime) {
         if (tokenLifetime == null) {
            throw new NullPointerException("tokenLifetime is marked non-null but is null");
         }

         this.tokenLifetime = tokenLifetime;
         return this;
      }

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

         this.accessToken = accessToken;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2TokenExchangeGrantAccessToken.OAuth2TokenExchangeGrantAccessTokenBuilder 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 OAuth2TokenExchangeGrantAccessToken build() {
         return new OAuth2TokenExchangeGrantAccessToken(this.issuedTokenType, this.tokenLifetime, this.accessToken, this.scope);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "OAuth2TokenExchangeGrantAccessToken.OAuth2TokenExchangeGrantAccessTokenBuilder(issuedTokenType="
            + this.issuedTokenType
            + ", tokenLifetime="
            + this.tokenLifetime
            + ", accessToken="
            + this.accessToken
            + ", scope="
            + this.scope
            + ")";
      }
   }
}
