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

import com.airlock.iam.oauth2.api.domain.model.OAuth2ClientId;
import com.airlock.iam.oauth2.api.domain.model.OAuth2Scope;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import lombok.NonNull;

public final class RemoteConsentRequestToken {
   @NonNull
   private final String userId;
   @NonNull
   private final List<OAuth2Scope> scope;
   @NonNull
   private final URI callbackUri;
   @NonNull
   private final OAuth2ClientId clientId;
   @NonNull
   private final Duration validity;

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

   @SuppressFBWarnings(justification = "generated code")
   private RemoteConsentRequestToken(
      @NonNull String userId, @NonNull List<OAuth2Scope> scope, @NonNull URI callbackUri, @NonNull OAuth2ClientId clientId, @NonNull Duration validity
   ) {
      if (userId == null) {
         throw new NullPointerException("userId is marked non-null but is null");
      }

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

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

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

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

      this.userId = userId;
      this.scope = scope;
      this.callbackUri = callbackUri;
      this.clientId = clientId;
      this.validity = validity;
   }

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

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

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class RemoteConsentRequestTokenBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String userId;
      @SuppressFBWarnings(justification = "generated code")
      private List<OAuth2Scope> scope;
      @SuppressFBWarnings(justification = "generated code")
      private URI callbackUri;
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ClientId clientId;
      @SuppressFBWarnings(justification = "generated code")
      private Duration validity;

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

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

         this.userId = userId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RemoteConsentRequestToken.RemoteConsentRequestTokenBuilder scope(@NonNull List<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 RemoteConsentRequestToken.RemoteConsentRequestTokenBuilder callbackUri(@NonNull URI callbackUri) {
         if (callbackUri == null) {
            throw new NullPointerException("callbackUri is marked non-null but is null");
         }

         this.callbackUri = callbackUri;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RemoteConsentRequestToken.RemoteConsentRequestTokenBuilder 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 RemoteConsentRequestToken.RemoteConsentRequestTokenBuilder validity(@NonNull Duration validity) {
         if (validity == null) {
            throw new NullPointerException("validity is marked non-null but is null");
         }

         this.validity = validity;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RemoteConsentRequestToken build() {
         return new RemoteConsentRequestToken(this.userId, this.scope, this.callbackUri, this.clientId, this.validity);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RemoteConsentRequestToken.RemoteConsentRequestTokenBuilder(userId="
            + this.userId
            + ", scope="
            + this.scope
            + ", callbackUri="
            + this.callbackUri
            + ", clientId="
            + this.clientId
            + ", validity="
            + this.validity
            + ")";
      }
   }
}
