package com.airlock.iam.login.app.misc.oauth2.introspection;

import com.airlock.iam.oauth2.api.domain.model.AuthorizationServerId;
import com.airlock.iam.oauth2.domain.model.logging.OAuth2TokenRepresentation;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.NonNull;

public class AsCentricOAuth2LogMessageAppender implements OAuth2LogMessageAppender {
   @NonNull
   private final OAuth2TokenRepresentation tokenRepresentation;
   @NonNull
   private final AuthorizationServerId authorizationServerId;

   @Override
   public String appendInstanceAndTokenInfos(String message, String tokenValue) {
      return message + " AS ID: '" + this.authorizationServerId.id() + "', token: " + this.tokenRepresentation.apply(tokenValue);
   }

   @SuppressFBWarnings(justification = "generated code")
   public AsCentricOAuth2LogMessageAppender(@NonNull OAuth2TokenRepresentation tokenRepresentation, @NonNull AuthorizationServerId authorizationServerId) {
      if (tokenRepresentation == null) {
         throw new NullPointerException("tokenRepresentation is marked non-null but is null");
      }

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

      this.tokenRepresentation = tokenRepresentation;
      this.authorizationServerId = authorizationServerId;
   }
}
