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

import com.airlock.iam.oauth2.api.domain.model.OAuth2ClientId;
import com.airlock.iam.oauth2.api.domain.model.OAuth2Scope;
import com.airlock.iam.oauth2.domain.model.OAuth2ResponseMode;
import com.airlock.iam.oauth2.domain.model.State;
import com.airlock.iam.oauth2.domain.model.authorization.OAuth2ResponseType;
import com.airlock.iam.oauth2.domain.model.session.PkceCodeChallenge;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URI;
import java.util.List;
import java.util.Optional;
import lombok.NonNull;

public record OAuth2AuthorizationRequestAttributes(
   @NonNull OAuth2ClientId clientId,
   @NonNull Optional<URI> requestedRedirectUri,
   @NonNull URI effectiveRedirectUri,
   @NonNull Optional<State> state,
   @NonNull Optional<PkceCodeChallenge> pkceChallenge,
   @NonNull OAuth2ResponseType responseType,
   @NonNull List<OAuth2Scope> requestedScopes,
   @NonNull OAuth2ResponseMode responseMode
) implements OAuth2OidcAuthorizationRequestAttributes {
   @SuppressFBWarnings(justification = "generated code")
   public OAuth2AuthorizationRequestAttributes {
      if (clientId == null) {
         throw new NullPointerException("clientId is marked non-null but is null");
      }

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

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

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

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

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

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

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

   @Override
   public boolean isOpenIdConnect() {
      return false;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class OAuth2AuthorizationRequestAttributesBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ClientId clientId;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<URI> requestedRedirectUri;
      @SuppressFBWarnings(justification = "generated code")
      private URI effectiveRedirectUri;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<State> state;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<PkceCodeChallenge> pkceChallenge;
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ResponseType responseType;
      @SuppressFBWarnings(justification = "generated code")
      private List<OAuth2Scope> requestedScopes;
      @SuppressFBWarnings(justification = "generated code")
      private OAuth2ResponseMode responseMode;

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

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder 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 OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder requestedRedirectUri(@NonNull Optional<URI> requestedRedirectUri) {
         if (requestedRedirectUri == null) {
            throw new NullPointerException("requestedRedirectUri is marked non-null but is null");
         }

         this.requestedRedirectUri = requestedRedirectUri;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder effectiveRedirectUri(@NonNull URI effectiveRedirectUri) {
         if (effectiveRedirectUri == null) {
            throw new NullPointerException("effectiveRedirectUri is marked non-null but is null");
         }

         this.effectiveRedirectUri = effectiveRedirectUri;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder state(@NonNull Optional<State> state) {
         if (state == null) {
            throw new NullPointerException("state is marked non-null but is null");
         }

         this.state = state;
         return this;
      }

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

         this.pkceChallenge = pkceChallenge;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder responseType(@NonNull OAuth2ResponseType responseType) {
         if (responseType == null) {
            throw new NullPointerException("responseType is marked non-null but is null");
         }

         this.responseType = responseType;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder requestedScopes(@NonNull List<OAuth2Scope> requestedScopes) {
         if (requestedScopes == null) {
            throw new NullPointerException("requestedScopes is marked non-null but is null");
         }

         this.requestedScopes = requestedScopes;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder responseMode(@NonNull OAuth2ResponseMode responseMode) {
         if (responseMode == null) {
            throw new NullPointerException("responseMode is marked non-null but is null");
         }

         this.responseMode = responseMode;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OAuth2AuthorizationRequestAttributes build() {
         return new OAuth2AuthorizationRequestAttributes(
            this.clientId,
            this.requestedRedirectUri,
            this.effectiveRedirectUri,
            this.state,
            this.pkceChallenge,
            this.responseType,
            this.requestedScopes,
            this.responseMode
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "OAuth2AuthorizationRequestAttributes.OAuth2AuthorizationRequestAttributesBuilder(clientId="
            + this.clientId
            + ", requestedRedirectUri="
            + this.requestedRedirectUri
            + ", effectiveRedirectUri="
            + this.effectiveRedirectUri
            + ", state="
            + this.state
            + ", pkceChallenge="
            + this.pkceChallenge
            + ", responseType="
            + this.responseType
            + ", requestedScopes="
            + this.requestedScopes
            + ", responseMode="
            + this.responseMode
            + ")";
      }
   }
}
