#include "ExceptionHandler.h"
#include "Logging.h"
#include <cstdlib>



const char* Create::Exceptions::ExceptionToString(Create::Exceptions::Type type) {
    switch (type) {
        case Create::Exceptions::None:          return "None";
        case Create::Exceptions::ComponentLoad: return "ComponentLoad";
        case Create::Exceptions::MissingField:  return "MissingField";
        case Create::Exceptions::InvalidFormat: return "InvalidFormat";
        case Create::Exceptions::SystemFailure: return "SystemFailure";
        case Create::Exceptions::AssetMissing:  return "AssetMissing";
        case Create::Exceptions::FileIO:        return "FileIO";
        case Create::Exceptions::RuntimeLogic:  return "RuntimeLogic";
        default:            return "Unknown";
    }
}

RecoverableError::RecoverableError(const std::string& msg, Create::Exceptions::Type type)
    : message(msg), type(type) {}

void RecoverableError::Handle() const {
    Logger::LogWarning("[Recoverable][%s] %s", ExceptionToString(type), message.c_str());
}

FatalError::FatalError(const std::string& msg, Create::Exceptions::Type type) {
    Logger::LogError("[Fatal][%s] %s", ExceptionToString(type), msg.c_str());
    std::exit(1);
}
