package com.airlock.iam.flow.shared.infrastructure.exception;

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.flow.domain.model.flow.NoFlowStartedException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

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

   public Response toResponse(NoFlowStartedException exception) {
      LOG.info("Cannot handle requests to flow endpoints before a flow has been started.");
      return ErrorResponse.forbidden().errorCode(IamRestErrorCode.UNEXPECTED_CALL).build().toResponse();
   }
}
