import {ErrorDialogData, errorMapper, ErrorType} from "./ErrorMapper";
import {ErrorDto} from "../../api/RequestBodyData";

class ErrorStore {
    mapErrorResponseToErrorDialogData = (errorDto: ErrorDto): ErrorDialogData => {
        let dialogMappedData = errorMapper.get(errorDto.exceptionType);
        if (!dialogMappedData){
            return {title: "Unchecked Error", content:"Unchecked Error Occurred."}
        }
        if(errorDto.detail){
            return {title: dialogMappedData.title, content:dialogMappedData.content.replace("_", `${errorDto.detail}`)} // TODO fix replacing of _ with more engineering approach
        }else{
            return dialogMappedData
        }
    }
}

export const createErrorStore = () => new ErrorStore();