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.session.NoFlowToContinueException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

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

   public Response toResponse(NoFlowToContinueException exception) {
      LOG.info("Expected flow to continue, but no current flow active. Probably session timeout.");
      return ErrorResponse.forbidden().errorCode(IamRestErrorCode.NO_FLOW_TO_CONTINUE).build().toResponse();
   }
}
