#pragma once

#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO

#include <DebugLog.h>
#include <Arduino.h>

#include <remoteIO.h>
#include <TCA9554PWR_Driver.h>

#define ON true
#define OFF false

class digitalIO
{

private:
    enum localInputs
    {
        DI1 = 4, // gpio for local inputs starts at 4 as per manufacturer documentation
        DI2,
        DI3,
        DI4,
        DI5,
        DI6,
        DI7,
        DI8,
        DI_MAX
    };

    const uint8_t maxRetries = 5;

public:
    digitalIO(drivers::I2C &i2c, drivers::MODBUS &bus, std::vector<uint8_t> remotes);
    ~digitalIO();

    void digitalIOWrite(const uint8_t ch, const bool value);
    const bool digitalIORead(const uint8_t ch);
    void reset();

    const uint8_t getOutNum();
    const uint8_t getInNum();

private:
    void digitalWriteLocal(const uint8_t ch, const bool value);
    void digitalWriteRemote(const uint8_t ch, const bool value);

    const bool digitalReadLocal(const uint8_t ch);
    const bool digitalReadRemote(const uint8_t ch);

private:
    std::vector<uint8_t> m_remoteAddrs;
    drivers::TCA9554PWR m_localOuts;
    std::vector<remoteIO> m_remotes;
};