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.Collection;
import java.util.Optional;
import java.util.Set;
import lombok.NonNull;

public final class RemoteConsentResponseToken {
   private final boolean consentGiven;
   @NonNull
   private final Optional<Set<OAuth2Scope>> scopes;

   public static RemoteConsentResponseToken tokenWithoutConsent() {
      return new RemoteConsentResponseToken(false, Optional.empty());
   }

   public static RemoteConsentResponseToken tokenWithConsentAndScopes(Collection<OAuth2Scope> scopes) {
      return new RemoteConsentResponseToken(true, Optional.of(Set.copyOf(scopes)));
   }

   @SuppressFBWarnings(justification = "generated code")
   private RemoteConsentResponseToken(boolean consentGiven, @NonNull Optional<Set<OAuth2Scope>> scopes) {
      if (scopes == null) {
         throw new NullPointerException("scopes is marked non-null but is null");
      }

      this.consentGiven = consentGiven;
      this.scopes = scopes;
   }

   @SuppressFBWarnings(justification = "generated code")
   public boolean consentGiven() {
      return this.consentGiven;
   }

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