#pragma once

#include <cstdint>
#include <cstring>
#include <exception>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>

namespace i2c
{

class I2CException : public std::exception
{
  public:
    explicit I2CException(const std::string& info, const std::string& bus,
                          uint8_t addr, int errorCode = 0) :
        bus(bus), addr(addr), errorCode(errorCode)
    {
        std::stringstream ss;
        ss << "I2CException: " << info << ": bus " << bus << ", addr 0x"
           << std::hex << static_cast<int>(addr);
        if (errorCode != 0)
        {
            ss << std::dec << ", errno " << errorCode << ": "
               << strerror(errorCode);
        }
        errStr = ss.str();
    }
    virtual ~I2CException() = default;

    const char* what() const noexcept override
    {
        return errStr.c_str();
    }
    std::string bus;
    uint8_t addr;
    int errorCode;
    std::string errStr;
};

class I2CInterface
{
  public:
    /** @brief Destructor
     *
     * Closes the I2C interface to the device if necessary.
     */
    virtual ~I2CInterface() = default;

    /** @brief Initial state when an I2CInterface object is created */
    enum class InitialState
    {
        OPEN,
        CLOSED
    };

    /** @brief The block transaction mode */
    enum class Mode
    {
        SMBUS,
        I2C,
    };

    /** @brief Open the I2C interface to the device
     *
     * Throws an I2CException if the interface is already open.  See isOpen().
     *
     * @throw I2CException on error
     */
    virtual void open() = 0;

    /** @brief Indicates whether the I2C interface to the device is open
     *
     * @return true if interface is open, false otherwise
     */
    virtual bool isOpen() const = 0;

    /** @brief Close the I2C interface to the device
     *
     * The interface can later be re-opened by calling open().
     *
     * Note that the destructor will automatically close the I2C interface if
     * necessary.
     *
     * Throws an I2CException if the interface is not open.  See isOpen().
     *
     * @throw I2CException on error
     */
    virtual void close() = 0;

    /** @brief Read byte data from i2c
     *
     * @param[out] data - The data read from the i2c device
     *
     * @throw I2CException on error
     */
    virtual void read(uint8_t& data) = 0;

    /** @brief Read byte data from i2c
     *
     * @param[in] addr - The register address of the i2c device
     * @param[out] data - The data read from the i2c device
     *
     * @throw I2CException on error
     */
    virtual void read(uint8_t addr, uint8_t& data) = 0;

    /** @brief Read word data from i2c
     *
     * Uses the SMBus Read Word protocol.  Reads two bytes from the device, and
     * the first byte read is the low-order byte.
     *
     * @param[in] addr - The register address of the i2c device
     * @param[out] data - The data read from the i2c device
     *
     * @throw I2CException on error
     */
    virtual void read(uint8_t addr, uint16_t& data) = 0;

    /** @brief Read block data from i2c
     *
     * @param[in] addr - The register address of the i2c device
     * @param[in,out] size - The out parameter to indicate the size of data read
     *                       from i2c device; when mode is I2C, it is also the
     *                       input parameter to indicate how many bytes to read
     * @param[out] data - The pointer to buffer to read from the i2c device,
     *                    the buffer shall be big enough to hold the data
     *                    returned by the device. SMBus allows at most 32
     *                    bytes.
     * @param[in] mode - The block read mode, either SMBus or I2C.
     *                   Internally, it invokes functions from libi2c:
     *                    * For SMBus: i2c_smbus_read_block_data()
     *                    * For I2C: i2c_smbus_read_i2c_block_data()
     *
     * @throw I2CException on error
     */
    virtual void read(uint8_t addr, uint8_t& size, uint8_t* data,
                      Mode mode = Mode::SMBUS) = 0;

    /** @brief Write byte data to i2c
     *
     * @param[in] data - The data to write to the i2c device
     *
     * @throw I2CException on error
     */
    virtual void write(uint8_t data) = 0;

    /** @brief Write byte data to i2c
     *
     * @param[in] addr - The register address of the i2c device
     * @param[in] data - The data to write to the i2c device
     *
     * @throw I2CException on error
     */
    virtual void write(uint8_t addr, uint8_t data) = 0;

    /** @brief Write word data to i2c
     *
     * Uses the SMBus Write Word protocol.  Writes two bytes to the device, and
     * the first byte written is the low-order byte.
     *
     * @param[in] addr - The register address of the i2c device
     * @param[in] data - The data to write to the i2c device
     *
     * @throw I2CException on error
     */
    virtual void write(uint8_t addr, uint16_t data) = 0;

    /** @brief Write block data to i2c
     *
     * @param[in] addr - The register address of the i2c device
     * @param[in] size - The size of data to write, SMBus allows at most 32
     *                   bytes
     * @param[in] data - The data to write to the i2c device
     * @param[in] mode - The block write mode, either SMBus or I2C.
     *                   Internally, it invokes functions from libi2c:
     *                    * For SMBus: i2c_smbus_write_block_data()
     *                    * For I2C: i2c_smbus_write_i2c_block_data()
     *
     * @throw I2CException on error
     */
    virtual void write(uint8_t addr, uint8_t size, const uint8_t* data,
                       Mode mode = Mode::SMBUS) = 0;
};

/** @brief Create an I2CInterface instance
 *
 * Automatically opens the I2CInterface if initialState is OPEN.
 *
 * @param[in] busId - The i2c bus ID
 * @param[in] devAddr - The device address of the i2c
 * @param[in] initialState - Initial state of the I2CInterface object
 * @param[in] maxRetries - Maximum number of times to retry an I2C operation
 *
 * @return The unique_ptr holding the I2CInterface
 */
std::unique_ptr<I2CInterface> create(
    uint8_t busId, uint8_t devAddr,
    I2CInterface::InitialState initialState = I2CInterface::InitialState::OPEN,
    int maxRetries = 0);

} // namespace i2c
