package com.airlock.iam.oauth2.infrastructure.exception.rest;

import com.airlock.iam.base.infrastructure.error.ErrorResponse;
import com.airlock.iam.common.infrastructure.exception.IamRestErrorCode;
import com.airlock.iam.elog.api.ELogger;
import com.airlock.iam.elog.api.ELoggerFactory;
import com.airlock.iam.oauth2.infrastructure.validation.UnconfiguredAuthorizationServerException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

@Provider
public final class OAuth2UnconfiguredAuthorizationServerExceptionMapper implements ExceptionMapper<UnconfiguredAuthorizationServerException> {
   private static final ELogger LOG = ELoggerFactory.getLogger(OAuth2UnconfiguredAuthorizationServerExceptionMapper.class);

   public Response toResponse(UnconfiguredAuthorizationServerException exception) {
      LOG.info(exception.getMessage());
      return ErrorResponse.notFound().errorCode(IamRestErrorCode.AUTHORIZATION_SERVER_NOT_FOUND).build().toResponse();
   }
}
