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

import com.airlock.iam.oauth2.api.domain.model.OAuth2Scope;
import com.airlock.iam.oauth2.domain.model.session.PkceCodeChallenge;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import java.util.Set;
import lombok.NonNull;

public record AuthorizationCodeInfo(
   @NonNull Set<OAuth2Scope> scopes, @NonNull Optional<String> redirectUriFromClient, @NonNull Optional<PkceCodeChallenge> pkceCodeChallenge
) {
   @SuppressFBWarnings(justification = "generated code")
   public AuthorizationCodeInfo {
      if (scopes == null) {
         throw new NullPointerException("scopes is marked non-null but is null");
      }

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class AuthorizationCodeInfoBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Set<OAuth2Scope> scopes;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<String> redirectUriFromClient;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<PkceCodeChallenge> pkceCodeChallenge;

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

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

         this.scopes = scopes;
         return this;
      }

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

         this.redirectUriFromClient = redirectUriFromClient;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public AuthorizationCodeInfo.AuthorizationCodeInfoBuilder pkceCodeChallenge(@NonNull Optional<PkceCodeChallenge> pkceCodeChallenge) {
         if (pkceCodeChallenge == null) {
            throw new NullPointerException("pkceCodeChallenge is marked non-null but is null");
         }

         this.pkceCodeChallenge = pkceCodeChallenge;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public AuthorizationCodeInfo build() {
         return new AuthorizationCodeInfo(this.scopes, this.redirectUriFromClient, this.pkceCodeChallenge);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "AuthorizationCodeInfo.AuthorizationCodeInfoBuilder(scopes="
            + this.scopes
            + ", redirectUriFromClient="
            + this.redirectUriFromClient
            + ", pkceCodeChallenge="
            + this.pkceCodeChallenge
            + ")";
      }
   }
}
