#include "dbus_environment.hpp"
#include "discrete_threshold.hpp"
#include "helpers.hpp"
#include "mocks/clock_mock.hpp"
#include "mocks/sensor_mock.hpp"
#include "mocks/trigger_action_mock.hpp"
#include "types/duration_types.hpp"
#include "utils/conv_container.hpp"

#include <gmock/gmock.h>

using namespace testing;
using namespace std::chrono_literals;

class TestDiscreteThreshold : public Test
{
  public:
    std::vector<std::shared_ptr<SensorMock>> sensorMocks = {
        std::make_shared<NiceMock<SensorMock>>(),
        std::make_shared<NiceMock<SensorMock>>()};
    std::vector<std::string> sensorNames = {"Sensor1", "Sensor2"};
    std::unique_ptr<TriggerActionMock> actionMockPtr =
        std::make_unique<StrictMock<TriggerActionMock>>();
    TriggerActionMock& actionMock = *actionMockPtr;
    std::shared_ptr<DiscreteThreshold> sut;
    std::string triggerId = "MyTrigger";
    std::unique_ptr<NiceMock<ClockMock>> clockMockPtr =
        std::make_unique<NiceMock<ClockMock>>();

    std::shared_ptr<DiscreteThreshold>
        makeThreshold(Milliseconds dwellTime, std::string thresholdValue,
                      discrete::Severity severity = discrete::Severity::ok,
                      std::string thresholdName = "treshold name")
    {
        std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
        actions.push_back(std::move(actionMockPtr));

        return std::make_shared<DiscreteThreshold>(
            DbusEnvironment::getIoc(), triggerId,
            utils::convContainer<std::shared_ptr<interfaces::Sensor>>(
                sensorMocks),
            std::move(actions), dwellTime, thresholdValue, thresholdName,
            severity, std::move(clockMockPtr));
    }

    void SetUp() override
    {
        for (size_t idx = 0; idx < sensorMocks.size(); idx++)
        {
            ON_CALL(*sensorMocks.at(idx), getName())
                .WillByDefault(Return(sensorNames[idx]));
        }

        sut = makeThreshold(0ms, "90.0", discrete::Severity::critical);
    }
};

TEST_F(TestDiscreteThreshold, initializeThresholdExpectAllSensorsAreRegistered)
{
    for (auto& sensor : sensorMocks)
    {
        EXPECT_CALL(*sensor,
                    registerForUpdates(Truly([sut = sut.get()](const auto& x) {
            return x.lock().get() == sut;
        })));
    }

    sut->initialize();
}

TEST_F(TestDiscreteThreshold, thresholdIsNotInitializeExpectNoActionCommit)
{
    EXPECT_CALL(actionMock, commit(_, _, _, _, _)).Times(0);
}

class TestDiscreteThresholdValues :
    public TestDiscreteThreshold,
    public WithParamInterface<std::string>
{};

INSTANTIATE_TEST_SUITE_P(_, TestDiscreteThresholdValues,
                         Values("90", ".90", "90.123", "0.0"));

TEST_P(TestDiscreteThresholdValues, thresholdValueIsNumericAndStoredCorrectly)
{
    sut = makeThreshold(0ms, GetParam(), discrete::Severity::critical);
    LabeledThresholdParam expected = discrete::LabeledThresholdParam(
        "treshold name", discrete::Severity::critical, 0, GetParam());
    EXPECT_EQ(sut->getThresholdParam(), expected);
}

class TestBadDiscreteThresholdValues :
    public TestDiscreteThreshold,
    public WithParamInterface<std::string>
{};

INSTANTIATE_TEST_SUITE_P(_, TestBadDiscreteThresholdValues,
                         Values("90ad", "ab.90", "x90", "On", "Off", ""));

TEST_P(TestBadDiscreteThresholdValues, throwsWhenNotNumericValues)
{
    EXPECT_THROW(makeThreshold(0ms, GetParam()), std::invalid_argument);
}

class TestDiscreteThresholdInit : public TestDiscreteThreshold
{
    void SetUp() override {}
};

TEST_F(TestDiscreteThresholdInit, nonEmptyNameIsNotChanged)
{
    auto sut = makeThreshold(0ms, "12.3", discrete::Severity::ok, "non-empty");
    EXPECT_THAT(
        std::get<discrete::LabeledThresholdParam>(sut->getThresholdParam())
            .at_label<utils::tstring::UserId>(),
        Eq("non-empty"));
}

TEST_F(TestDiscreteThresholdInit, emptyNameIsChanged)
{
    auto sut = makeThreshold(0ms, "12.3", discrete::Severity::ok, "");
    EXPECT_THAT(
        std::get<discrete::LabeledThresholdParam>(sut->getThresholdParam())
            .at_label<utils::tstring::UserId>(),
        Not(Eq("")));
}

struct DiscreteParams
{
    struct UpdateParams
    {
        size_t sensor;
        double value;
        Milliseconds sleepAfter;

        UpdateParams(size_t sensor, double value,
                     Milliseconds sleepAfter = 0ms) :
            sensor(sensor),
            value(value), sleepAfter(sleepAfter)
        {}
    };

    struct ExpectedParams
    {
        size_t sensor;
        double value;
        Milliseconds waitMin;

        ExpectedParams(size_t sensor, double value,
                       Milliseconds waitMin = 0ms) :
            sensor(sensor),
            value(value), waitMin(waitMin)
        {}
    };

    DiscreteParams& Updates(std::vector<UpdateParams> val)
    {
        updates = std::move(val);
        return *this;
    }

    DiscreteParams& Expected(std::vector<ExpectedParams> val)
    {
        expected = std::move(val);
        return *this;
    }

    DiscreteParams& ThresholdValue(std::string val)
    {
        thresholdValue = std::move(val);
        return *this;
    }

    DiscreteParams& DwellTime(Milliseconds val)
    {
        dwellTime = std::move(val);
        return *this;
    }

    friend void PrintTo(const DiscreteParams& o, std::ostream* os)
    {
        *os << "{ DwellTime: " << o.dwellTime.count() << "ms ";
        *os << ", ThresholdValue: " << o.thresholdValue;
        *os << ", Updates: [ ";
        for (const auto& [index, value, sleepAfter] : o.updates)
        {
            *os << "{ SensorIndex: " << index << ", Value: " << value
                << ", SleepAfter: " << sleepAfter.count() << "ms }, ";
        }
        *os << " ] Expected: [ ";
        for (const auto& [index, value, waitMin] : o.expected)
        {
            *os << "{ SensorIndex: " << index << ", Value: " << value
                << ", waitMin: " << waitMin.count() << "ms }, ";
        }
        *os << " ] }";
    }

    std::vector<UpdateParams> updates;
    std::vector<ExpectedParams> expected;
    std::string thresholdValue = "0.0";
    Milliseconds dwellTime = 0ms;
};

class TestDiscreteThresholdCommon :
    public TestDiscreteThreshold,
    public WithParamInterface<DiscreteParams>
{
  public:
    void sleep(Milliseconds duration)
    {
        if (duration != 0ms)
        {
            DbusEnvironment::sleepFor(duration);
        }
    }

    void testBodySensorIsUpdatedMultipleTimes()
    {
        std::vector<std::chrono::time_point<std::chrono::high_resolution_clock>>
            timestamps(sensorMocks.size());

        sut->initialize();

        InSequence seq;

        for (const auto& [index, value, waitMin] : GetParam().expected)
        {
            EXPECT_CALL(actionMock,
                        commit(triggerId, Optional(StrEq("treshold name")),
                               sensorNames[index], _,
                               TriggerValue(GetParam().thresholdValue)))
                .WillOnce(DoAll(
                    InvokeWithoutArgs([idx = index, &timestamps] {
                timestamps[idx] = std::chrono::high_resolution_clock::now();
            }),
                    InvokeWithoutArgs(DbusEnvironment::setPromise("commit"))));
        }

        auto start = std::chrono::high_resolution_clock::now();

        for (const auto& [index, value, sleepAfter] : GetParam().updates)
        {
            sut->sensorUpdated(*sensorMocks[index], 42ms, value);
            sleep(sleepAfter);
        }

        EXPECT_THAT(DbusEnvironment::waitForFutures("commit"), true);
        for (const auto& [index, value, waitMin] : GetParam().expected)
        {
            EXPECT_THAT(timestamps[index] - start, Ge(waitMin));
        }
    }
};

class TestDiscreteThresholdNoDwellTime : public TestDiscreteThresholdCommon
{
  public:
    void SetUp() override
    {
        for (size_t idx = 0; idx < sensorMocks.size(); idx++)
        {
            ON_CALL(*sensorMocks.at(idx), getName())
                .WillByDefault(Return(sensorNames[idx]));
        }

        sut = makeThreshold(0ms, GetParam().thresholdValue);
    }
};

INSTANTIATE_TEST_SUITE_P(
    _, TestDiscreteThresholdNoDwellTime,
    Values(DiscreteParams()
               .ThresholdValue("90.0")
               .Updates({{0, 80.0}, {0, 89.0}})
               .Expected({}),
           DiscreteParams()
               .ThresholdValue("90.0")
               .Updates({{0, 80.0}, {0, 90.0}, {0, 80.0}, {0, 90.0}})
               .Expected({{0, 90.0}, {0, 90.0}}),
           DiscreteParams()
               .ThresholdValue("90.0")
               .Updates({{0, 90.0}, {0, 99.0}, {1, 100.0}, {1, 90.0}})
               .Expected({{0, 90.0}, {1, 90.0}})));

TEST_P(TestDiscreteThresholdNoDwellTime, senorsIsUpdatedMultipleTimes)
{
    testBodySensorIsUpdatedMultipleTimes();
}

class TestDiscreteThresholdWithDwellTime : public TestDiscreteThresholdCommon
{
  public:
    void SetUp() override
    {
        for (size_t idx = 0; idx < sensorMocks.size(); idx++)
        {
            ON_CALL(*sensorMocks.at(idx), getName())
                .WillByDefault(Return(sensorNames[idx]));
        }

        sut = makeThreshold(GetParam().dwellTime, GetParam().thresholdValue);
    }
};

INSTANTIATE_TEST_SUITE_P(
    _, TestDiscreteThresholdWithDwellTime,
    Values(DiscreteParams()
               .DwellTime(200ms)
               .ThresholdValue("90.0")
               .Updates({{0, 90.0, 100ms}, {0, 91.0}, {0, 90.0}})
               .Expected({{0, 90.0, 300ms}}),
           DiscreteParams()
               .DwellTime(100ms)
               .ThresholdValue("90.0")
               .Updates({{0, 90.0, 100ms}})
               .Expected({{0, 90.0, 100ms}}),
           DiscreteParams()
               .DwellTime(1000ms)
               .ThresholdValue("90.0")
               .Updates({{0, 90.0, 700ms},
                         {0, 91.0, 100ms},
                         {0, 90.0, 300ms},
                         {0, 91.0, 100ms}})
               .Expected({}),
           DiscreteParams()
               .DwellTime(200ms)
               .ThresholdValue("90.0")
               .Updates({{0, 90.0},
                         {1, 89.0, 100ms},
                         {1, 90.0, 100ms},
                         {1, 89.0, 100ms},
                         {1, 90.0, 300ms},
                         {1, 89.0, 100ms}})
               .Expected({{0, 90, 200ms}, {1, 90, 500ms}})));

TEST_P(TestDiscreteThresholdWithDwellTime, senorsIsUpdatedMultipleTimes)
{
    testBodySensorIsUpdatedMultipleTimes();
}
