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

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

   public Response toResponse(FlowNotAllowedException exception) {
      LOG.info("Not allowed to start flow because the user session already contains data.");
      return ErrorResponse.forbidden().errorCode(IamRestErrorCode.FLOW_START_NOT_ALLOWED).build().toResponse();
   }
}
