#include "../fallback.hpp"

#include "../psensor.hpp"

#include <iostream>
#include <string>

#include <gtest/gtest.h>

int pstate = -1;

namespace phosphor
{
namespace fan
{
namespace presence
{
void setPresence(const Fan&, bool newState)
{
    if (newState)
    {
        pstate = 1;
    }
    else
    {
        pstate = 0;
    }
}

class TestSensor : public PresenceSensor
{
  public:
    bool start() override
    {
        ++started;
        return _present;
    }

    void stop() override
    {
        ++stopped;
    }

    bool present() override
    {
        return _present;
    }

    void fail() override
    {
        ++failed;
    }

    bool _present = false;
    size_t started = 0;
    size_t stopped = 0;
    size_t failed = 0;
};

} // namespace presence
} // namespace fan
} // namespace phosphor

using namespace phosphor::fan::presence;

TEST(FallbackTest, TestOne)
{
    // Validate a single sensor.
    // Validate on->off->on.
    pstate = -1;
    Fan fan{"/path", "name", 0};
    TestSensor ts;
    ts._present = true;
    std::vector<std::reference_wrapper<PresenceSensor>> sensors{ts};
    Fallback f{fan, sensors};

    f.monitor();
    ASSERT_EQ(pstate, 1);
    ASSERT_EQ(ts.failed, 0);
    ASSERT_EQ(ts.stopped, 0);
    ASSERT_EQ(ts.started, 1);

    f.stateChanged(false);
    ASSERT_EQ(pstate, 0);
    ASSERT_EQ(ts.failed, 0);
    ASSERT_EQ(ts.stopped, 0);
    ASSERT_EQ(ts.started, 1);

    f.stateChanged(true);
    ASSERT_EQ(pstate, 1);
    ASSERT_EQ(ts.failed, 0);
    ASSERT_EQ(ts.stopped, 0);
    ASSERT_EQ(ts.started, 1);
}

TEST(FallbackTest, TestTwoA)
{
    // Validate two sensors.
    // Validate both sensors on->off->on

    pstate = -1;
    Fan fan{"/path", "name", 0};
    TestSensor ts1, ts2;
    ts1._present = true;
    ts2._present = true;

    std::vector<std::reference_wrapper<PresenceSensor>> sensors{ts1, ts2};
    Fallback f{fan, sensors};

    f.monitor();
    ASSERT_EQ(pstate, 1);
    ASSERT_EQ(ts1.failed, 0);
    ASSERT_EQ(ts1.stopped, 0);
    ASSERT_EQ(ts1.started, 1);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 0);

    ts1._present = false;
    ts2._present = false;
    f.stateChanged(false);
    ASSERT_EQ(pstate, 0);
    ASSERT_EQ(ts1.failed, 0);
    ASSERT_EQ(ts1.stopped, 0);
    ASSERT_EQ(ts1.started, 1);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 0);

    ts1._present = true;
    ts2._present = true;
    f.stateChanged(true);
    ASSERT_EQ(pstate, 1);
    ASSERT_EQ(ts1.failed, 0);
    ASSERT_EQ(ts1.stopped, 0);
    ASSERT_EQ(ts1.started, 1);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 0);
}

TEST(FallbackTest, TestTwoB)
{
    // Validate two sensors.
    // Validate first sensor on->off.

    pstate = -1;
    Fan fan{"/path", "name"};
    TestSensor ts1, ts2;
    ts1._present = true;
    ts2._present = true;

    std::vector<std::reference_wrapper<PresenceSensor>> sensors{ts1, ts2};
    Fallback f{fan, sensors};

    f.monitor();
    ASSERT_EQ(pstate, 1);
    ts1._present = false;
    f.stateChanged(false);
    ASSERT_EQ(pstate, 1);
    ASSERT_EQ(ts1.failed, 1);
    ASSERT_EQ(ts1.stopped, 1);
    ASSERT_EQ(ts1.started, 1);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 1);

    // Flip the state of both sensors.
    ts1._present = true;
    ts2._present = false;
    f.stateChanged(false);
    ASSERT_EQ(pstate, 0);
    ASSERT_EQ(ts1.failed, 1);
    ASSERT_EQ(ts1.stopped, 1);
    ASSERT_EQ(ts1.started, 1);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 1);
}

TEST(FallbackTest, TestTwoC)
{
    // Validate two sensors.
    // Validate first in bad state.

    pstate = -1;
    Fan fan{"/path", "name"};
    TestSensor ts1, ts2;
    ts1._present = false;
    ts2._present = true;

    std::vector<std::reference_wrapper<PresenceSensor>> sensors{ts1, ts2};
    Fallback f{fan, sensors};

    f.monitor();
    ASSERT_EQ(pstate, 1);
    ASSERT_EQ(ts1.failed, 1);
    ASSERT_EQ(ts1.stopped, 0);
    ASSERT_EQ(ts1.started, 0);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 1);

    f.stateChanged(false);
    ASSERT_EQ(pstate, 0);
    ASSERT_EQ(ts1.failed, 1);
    ASSERT_EQ(ts1.stopped, 0);
    ASSERT_EQ(ts1.started, 0);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 1);
}

TEST(FallbackTest, TestTwoD)
{
    // Validate two sensors.
    // Validate both in bad state.

    pstate = -1;
    Fan fan{"/path", "name"};
    TestSensor ts1, ts2;
    ts1._present = false;
    ts2._present = false;

    std::vector<std::reference_wrapper<PresenceSensor>> sensors{ts1, ts2};
    Fallback f{fan, sensors};

    f.monitor();
    ASSERT_EQ(pstate, 0);
    ASSERT_EQ(ts1.failed, 0);
    ASSERT_EQ(ts1.stopped, 0);
    ASSERT_EQ(ts1.started, 1);
    ASSERT_EQ(ts2.failed, 0);
    ASSERT_EQ(ts2.stopped, 0);
    ASSERT_EQ(ts2.started, 0);
}
