package com.banesco.commons.exceptions;

import com.banesco.common.domain.dto.bian.response.StatusResponse;
import com.banesco.domain.bian.response.RecUpdateCardStatusResponse;
import io.vertx.ext.web.RoutingContext;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.jboss.resteasy.reactive.server.UnwrapException;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletionException;

@UnwrapException({CompletionException.class, BanConfigException.class})
@Slf4j
public class InternalExceptionMapper {

    @Inject
    RoutingContext routingContext; // Injecting the RoutingContext

    @ServerExceptionMapper
    public Response handleConfigException(Exception ex) {
        String uri = routingContext.request().uri();

        switch (uri) {

            case "/card/status/update":
                RecUpdateCardStatusResponse response = new RecUpdateCardStatusResponse();
                response.setStatusResponse(
                        new StatusResponse(
                                "error",
                                "CONFLICT",
                                "Uso interno",
                                null
                        )
                );
                return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                        .entity(response.toString())
                        .build();
            default:


        }

        Map<String, String> errorMap = new HashMap<>();
        errorMap.put("error", "USO INTERNO");


        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                .entity(errorMap).build();
    }

}