#include "env_mock.hpp"
#include "gpio_mock.hpp"
#include "hwmonio_mock.hpp"
#include "sensor.hpp"

#include <gpioplus/test/handle.hpp>

#include <memory>
#include <utility>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace env
{

// Delegate all calls to getEnv() to the mock
const char* EnvImpl::get(const char* key) const
{
    return mockEnv.get(key);
}

EnvImpl env_impl;

} // namespace env

class SensorTest : public ::testing::Test
{
  protected:
    void SetUp() override
    {
        gpioIntf = nullptr;
    }

    std::string temp = "temp";
    std::string five = "5";
};

using ::testing::Eq;
using ::testing::Invoke;
using ::testing::Pair;
using ::testing::Return;
using ::testing::StrEq;
using ::testing::StrictMock;

TEST_F(SensorTest, BasicConstructorTest)
{
    /* Constructor test with nothing in an rcList or GPIO chip. */
    auto sensorKey = std::make_pair(temp, five);
    std::unique_ptr<hwmonio::HwmonIOInterface> hwmonio_mock =
        std::make_unique<hwmonio::HwmonIOMock>();
    std::string path = "/";

    /* Always calls GPIOCHIP and GPIO checks, returning empty string. */
    EXPECT_CALL(env::mockEnv, get(StrEq("GPIOCHIP_temp5")))
        .WillOnce(Return(""));
    EXPECT_CALL(env::mockEnv, get(StrEq("GPIO_temp5"))).WillOnce(Return(""));

    /* Always calls GAIN and OFFSET, can use ON_CALL instead of EXPECT_CALL */
    EXPECT_CALL(env::mockEnv, get(StrEq("GAIN_temp5"))).WillOnce(Return(""));
    EXPECT_CALL(env::mockEnv, get(StrEq("OFFSET_temp5"))).WillOnce(Return(""));
    EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
        .WillOnce(Return(""));

    auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
                                                   hwmonio_mock.get(), path);
    EXPECT_FALSE(sensor == nullptr);
}

TEST_F(SensorTest, SensorRequiresGpio)
{
    /* Constructor test with only the GPIO chip set. */

    StrictMock<GpioHandleMock> gMock;
    gpioIntf = &gMock;

    /* The following piece of code can probably be copied above once it's
     * working.
     */
    auto handleMock = std::make_unique<gpioplus::test::HandleMock>();

    auto sensorKey = std::make_pair(temp, five);
    std::unique_ptr<hwmonio::HwmonIOInterface> hwmonio_mock =
        std::make_unique<hwmonio::HwmonIOMock>();
    std::string path = "/";

    EXPECT_CALL(env::mockEnv, get(StrEq("GPIOCHIP_temp5")))
        .WillOnce(Return("chipA"));
    EXPECT_CALL(env::mockEnv, get(StrEq("GPIO_temp5"))).WillOnce(Return("5"));

    EXPECT_CALL(gMock, build(StrEq("chipA"), StrEq("5")))
        .WillOnce(Invoke([&](const std::string&, const std::string&) {
        return std::move(handleMock);
    }));

    /* Always calls GAIN and OFFSET, can use ON_CALL instead of EXPECT_CALL */
    EXPECT_CALL(env::mockEnv, get(StrEq("GAIN_temp5"))).WillOnce(Return(""));
    EXPECT_CALL(env::mockEnv, get(StrEq("OFFSET_temp5"))).WillOnce(Return(""));
    EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
        .WillOnce(Return(""));

    auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
                                                   hwmonio_mock.get(), path);
    EXPECT_FALSE(sensor == nullptr);
}

TEST_F(SensorTest, SensorHasGainAndOffsetAdjustValue)
{
    /* Construct a sensor that has a gain and offset, then verify they are used
     * when adjusting the value.
     */

    auto sensorKey = std::make_pair(temp, five);
    std::unique_ptr<hwmonio::HwmonIOInterface> hwmonio_mock =
        std::make_unique<hwmonio::HwmonIOMock>();
    std::string path = "/";

    /* Always calls GPIOCHIP_temp5 and GPIO checks, returning empty string. */
    EXPECT_CALL(env::mockEnv, get(StrEq("GPIOCHIP_temp5")))
        .WillOnce(Return(""));
    EXPECT_CALL(env::mockEnv, get(StrEq("GPIO_temp5"))).WillOnce(Return(""));

    EXPECT_CALL(env::mockEnv, get(StrEq("GAIN_temp5"))).WillOnce(Return("10"));
    EXPECT_CALL(env::mockEnv, get(StrEq("OFFSET_temp5")))
        .WillOnce(Return("15"));
    EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
        .WillOnce(Return(""));

    auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
                                                   hwmonio_mock.get(), path);
    EXPECT_FALSE(sensor == nullptr);

    double startingValue = 1.0;
    double resultValue = sensor->adjustValue(startingValue);
    EXPECT_DOUBLE_EQ(resultValue, 25.0);
}
