#pragma once

#include <string>
#include <utility>

namespace tw::msg {

enum class MessageErrorType {
    NotConnected,
    SendFailed,
    BindFailed,
    ConnectFailed,
};

struct MessageError {
    MessageErrorType type;
    std::string      detail;

    explicit MessageError(MessageErrorType type, std::string detail = {}) :
        type(type),
        detail(std::move(detail)) {
    }

    std::string message() const {
        std::string text;
        switch(type) {
            case MessageErrorType::NotConnected:  text = "Not connected to the peer"; break;
            case MessageErrorType::SendFailed:    text = "Failed to send the message"; break;
            case MessageErrorType::BindFailed:    text = "Failed to bind the endpoint"; break;
            case MessageErrorType::ConnectFailed: text = "Failed to connect to the peer"; break;
        }

        return detail.empty() ? text : text + ": " + detail;
    }
};

}
