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

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

public final class RemoteConsentVerificationResult {
   private final RemoteConsentVerificationResult.RemoteConsentVerificationResultType type;
   private final Optional<Set<OAuth2Scope>> grantedScope;

   public static RemoteConsentVerificationResult consentGivenWithScope(Set<OAuth2Scope> scopes) {
      return new RemoteConsentVerificationResult(
         RemoteConsentVerificationResult.RemoteConsentVerificationResultType.CONSENT_GIVEN_WITH_SCOPE, Optional.of(Set.copyOf(scopes))
      );
   }

   public static RemoteConsentVerificationResult consentDenied() {
      return new RemoteConsentVerificationResult(RemoteConsentVerificationResult.RemoteConsentVerificationResultType.CONSENT_DENIED, Optional.empty());
   }

   public static RemoteConsentVerificationResult jwtInvalid() {
      return new RemoteConsentVerificationResult(RemoteConsentVerificationResult.RemoteConsentVerificationResultType.JWT_INVALID, Optional.empty());
   }

   @SuppressFBWarnings(justification = "generated code")
   private RemoteConsentVerificationResult(RemoteConsentVerificationResult.RemoteConsentVerificationResultType type, Optional<Set<OAuth2Scope>> grantedScope) {
      this.type = type;
      this.grantedScope = grantedScope;
   }

   @SuppressFBWarnings(justification = "generated code")
   public RemoteConsentVerificationResult.RemoteConsentVerificationResultType type() {
      return this.type;
   }

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

   public enum RemoteConsentVerificationResultType {
      CONSENT_GIVEN_WITH_SCOPE,
      CONSENT_DENIED,
      JWT_INVALID;
   }
}
