#pragma once
#include "types.hpp"

#include <boost/asio/steady_timer.hpp>
#include <nlohmann/json.hpp>
#include <sdbusplus/asio/connection.hpp>

namespace openpower
{
namespace vpd
{
namespace manager
{
/** @class GpioEventHandler
 *  @brief Responsible for catching the event and handle it.
 *         This keeps checking for the FRU's presence.
 *         If any attachment or de-attachment found, it enables/disables that
 * fru's output gpio and bind/unbind the driver, respectively.
 */
class GpioEventHandler
{
  public:
    GpioEventHandler() = default;
    ~GpioEventHandler() = default;
    GpioEventHandler(const GpioEventHandler&) = default;
    GpioEventHandler& operator=(const GpioEventHandler&) = delete;
    GpioEventHandler(GpioEventHandler&&) = delete;
    GpioEventHandler& operator=(GpioEventHandler&&) = delete;

    GpioEventHandler(std::string& presPin, Byte& presValue, std::string& outPin,
                     Byte& outValue, std::string& devAddr, std::string& driver,
                     std::string& bus, std::string& objPath,
                     std::shared_ptr<boost::asio::io_context>& ioCon) :
        presencePin(presPin), presenceValue(presValue), outputPin(outPin),
        outputValue(outValue), devNameAddr(devAddr), driverType(driver),
        busType(bus), objectPath(objPath)
    {
        doEventAndTimerSetup(ioCon);
    }

  private:
    /** @brief GPIO information to get parsed from vpd json*/

    // gpio pin indicates presence/absence of fru
    const std::string presencePin;
    // value which means fru is present
    const Byte presenceValue;
    // gpio pin to enable If fru is present
    const std::string outputPin;
    // Value to set, to enable the output pin
    const Byte outputValue;

    // FRU address on bus
    const std::string devNameAddr;
    // Driver type
    const std::string driverType;
    // Bus type
    const std::string busType;
    // object path of FRU
    const std::string objectPath;

    /** Preserves the GPIO pin value to compare it next time. Default init by
     *  false*/
    bool prevPresPinValue = false;

    /** @brief This is a helper function to read the
     *        current value of Presence GPIO
     *
     *  @returns The GPIO value
     */
    bool getPresencePinValue();

    /** @brief This function will toggle the output gpio as per the presence
     *         state of fru.
     */
    void toggleGpio();

    /** @brief This function checks for fru's presence pin and detects change of
     *         value on that pin, (in case of fru gets attached or de-attached).
     *
     *  @returns true if presence pin value changed
     *           false otherwise
     */
    inline bool hasEventOccurred()
    {
        return getPresencePinValue() != prevPresPinValue;
    }

    /** @brief This function runs a timer , which keeps checking for if an event
     *         happened, if event occurred then takes action.
     *
     *  @param[in] ioContext - Pointer to io context object.
     */
    void doEventAndTimerSetup(
        std::shared_ptr<boost::asio::io_context>& ioContext);

    /**
     * @brief Api to handle timer expiry.
     *
     * @param ec - Error code.
     * @param timer - Pointer to timer object.
     */
    void handleTimerExpiry(const boost::system::error_code& ec,
                           std::shared_ptr<boost::asio::steady_timer>& timer);
};

/** @class GpioMonitor
 *  @brief Responsible for initialising the private variables containing gpio
 *         infos. These information will be fetched from vpd json.
 */
class GpioMonitor
{
  public:
    GpioMonitor() = delete;
    ~GpioMonitor() = default;
    GpioMonitor(const GpioMonitor&) = delete;
    GpioMonitor& operator=(const GpioMonitor&) = delete;
    GpioMonitor(GpioMonitor&&) = delete;
    GpioMonitor& operator=(GpioMonitor&&) = delete;

    GpioMonitor(nlohmann::json& js,
                std::shared_ptr<boost::asio::io_context>& ioCon) : jsonFile(js)
    {
        initGpioInfos(ioCon);
    }

  private:
    // Json file to get the data
    nlohmann::json& jsonFile;
    // Array of event handlers for all the attachable FRUs
    std::vector<std::shared_ptr<GpioEventHandler>> gpioObjects;

    /** @brief This function will extract the gpio information from vpd json
     * and store it in GpioEventHandler's private variables
     *
     * @param[in] ioContext - Pointer to io context object.
     */
    void initGpioInfos(std::shared_ptr<boost::asio::io_context>& ioContext);
};

} // namespace manager
} // namespace vpd
} // namespace openpower
