package org.flowcolab.util.spring.web.error;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;

import java.util.Arrays;

public interface ExceptionMapper {

    static final String ErrorCodeHeader = "AppErrorCode";

    String getCode();

    HttpStatus getHttpStatus();

    Class<?> getExceptionClass();

    Class<?> getDtoClass();

    Exception getExceptionFromDtoObject(Object ex);

    Object getDtoFromExceptionObject(Exception dto);

    ResponseEntity getResponseEntityObject(Exception ex);

    Exception getExceptionFromResponseEntityObject(ResponseEntity responseEntity);

    default void throwFromResponseEntityObject(ResponseEntity responseEntity) throws Exception {
        Exception ex = getExceptionFromResponseEntityObject(responseEntity);
        if(ex != null) {
            throw ex;
        }
    }
}
