#pragma once

#include <exception>
#include <map>
#include <string>

namespace ipmiblob
{

class IpmiException : public std::exception
{
  public:
    IpmiException(const std::string& message, int code) :
        _message(message), _ccode(code) {};

    static std::string messageFromIpmi(int cc)
    {
        const std::map<int, std::string> commonFailures = {
            {0xc0, "busy"},
            {0xc1, "invalid"},
            {0xc3, "timeout"},
        };

        auto search = commonFailures.find(cc);
        if (search != commonFailures.end())
        {
            return "Received IPMI_CC: " + search->second;
        }
        else
        {
            return "Received IPMI_CC: " + std::to_string(cc);
        }
    }

    /* This will leave the code as 0, but by virtue of being an exception
     * thrown, we'll know it was an error on the host-side.
     */
    explicit IpmiException(const std::string& message) : _message(message) {}

    explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc), cc) {}

    virtual const char* what() const noexcept override
    {
        return _message.c_str();
    }

    int code() const noexcept
    {
        return _ccode;
    }

  private:
    std::string _message;
    int _ccode = 0;
};

} // namespace ipmiblob
