#include "dbus_environment.hpp"
#include "fakes/clock_fake.hpp"
#include "helpers.hpp"
#include "messages/collect_trigger_id.hpp"
#include "messages/trigger_presence_changed_ind.hpp"
#include "messages/update_report_ind.hpp"
#include "mocks/json_storage_mock.hpp"
#include "mocks/metric_mock.hpp"
#include "mocks/report_factory_mock.hpp"
#include "mocks/report_manager_mock.hpp"
#include "params/report_params.hpp"
#include "report.hpp"
#include "report_manager.hpp"
#include "utils/clock.hpp"
#include "utils/contains.hpp"
#include "utils/conv_container.hpp"
#include "utils/messanger.hpp"
#include "utils/transform.hpp"
#include "utils/tstring.hpp"

#include <sdbusplus/exception.hpp>

using namespace testing;
using namespace std::literals::string_literals;
using namespace std::chrono_literals;
namespace tstring = utils::tstring;

constexpr Milliseconds systemTimestamp = 55ms;

namespace
{

ReportParams defaultParams()
{
    return ReportParams();
}

ReportParams defaultOnChangeParams()
{
    return defaultParams().reportingType(ReportingType::onChange);
}

} // namespace

class TestReport : public Test
{
  public:
    std::unique_ptr<ReportManagerMock> reportManagerMock =
        std::make_unique<NiceMock<ReportManagerMock>>();
    std::unique_ptr<ReportFactoryMock> reportFactoryMock =
        std::make_unique<NiceMock<ReportFactoryMock>>();
    nlohmann::json storedConfiguration;
    NiceMock<StorageMock> storageMock;
    std::vector<std::shared_ptr<MetricMock>> metricMocks;
    std::unique_ptr<ClockFake> clockFakePtr = std::make_unique<ClockFake>();
    ClockFake& clockFake = *clockFakePtr;
    std::unique_ptr<Report> sut;
    utils::Messanger messanger;

    MockFunction<void()> checkPoint;

    TestReport() : messanger(DbusEnvironment::getIoc())
    {
        clockFake.system.set(systemTimestamp);
        ON_CALL(storageMock, store(to_file_path(ReportParams().reportId()), _))
            .WillByDefault(SaveArg<1>(&storedConfiguration));
    }

    void initMetricMocks(
        const std::vector<LabeledMetricParameters>& metricParameters)
    {
        for (auto i = metricMocks.size(); i < metricParameters.size(); ++i)
        {
            metricMocks.emplace_back(std::make_shared<NiceMock<MetricMock>>());
        }
        metricMocks.resize(metricParameters.size());

        std::vector<MetricValue> readings{{MetricValue{"a", "b", 17.1, 114},
                                           MetricValue{"aa", "bb", 42.0, 74}}};
        readings.resize(metricParameters.size());

        for (size_t i = 0; i < metricParameters.size(); ++i)
        {
            ON_CALL(*metricMocks[i], getUpdatedReadings())
                .WillByDefault(ReturnRefOfCopy(std::vector({readings[i]})));
            ON_CALL(*metricMocks[i], dumpConfiguration())
                .WillByDefault(Return(metricParameters[i]));
        }
    }

    std::vector<std::shared_ptr<interfaces::Metric>>
        getMetricsFromReadingParams(const ReadingParameters& params)
    {
        const auto metricParameters =
            reportFactoryMock->convertMetricParams(params);
        std::vector<std::shared_ptr<MetricMock>> metricMocks;

        for (size_t i = 0; i < metricParameters.size(); ++i)
        {
            metricMocks.emplace_back(std::make_shared<NiceMock<MetricMock>>());
            ON_CALL(*metricMocks[i], dumpConfiguration())
                .WillByDefault(Return(metricParameters[i]));
        }

        return utils::convContainer<std::shared_ptr<interfaces::Metric>>(
            metricMocks);
    }

    void SetUp() override
    {
        sut = makeReport(defaultParams());
    }

    static interfaces::JsonStorage::FilePath to_file_path(std::string id)
    {
        return interfaces::JsonStorage::FilePath(
            std::to_string(std::hash<std::string>{}(id)));
    }

    std::unique_ptr<Report> makeReport(const ReportParams& params)
    {
        initMetricMocks(params.metricParameters());

        return std::make_unique<Report>(
            DbusEnvironment::getIoc(), DbusEnvironment::getObjServer(),
            params.reportId(), params.reportName(), params.reportingType(),
            params.reportActions(), params.interval(), params.appendLimit(),
            params.reportUpdates(), *reportManagerMock, storageMock,
            utils::convContainer<std::shared_ptr<interfaces::Metric>>(
                metricMocks),
            *reportFactoryMock, params.enabled(), std::move(clockFakePtr),
            params.readings());
    }

    template <class T>
    static T getProperty(const std::string& path, const std::string& property)
    {
        return DbusEnvironment::getProperty<T>(path, Report::reportIfaceName,
                                               property);
    }

    template <class T>
    static boost::system::error_code setProperty(const std::string& path,
                                                 const std::string& property,
                                                 const T& newValue)
    {
        return DbusEnvironment::setProperty<T>(path, Report::reportIfaceName,
                                               property, newValue);
    }

    boost::system::error_code call(const std::string& path,
                                   const std::string& interface,
                                   const std::string& method)
    {
        std::promise<boost::system::error_code> methodPromise;
        DbusEnvironment::getBus()->async_method_call(
            [&methodPromise](boost::system::error_code ec) {
                methodPromise.set_value(ec);
            },
            DbusEnvironment::serviceName(), path, interface, method);
        return DbusEnvironment::waitForFuture(methodPromise.get_future());
    }

    boost::system::error_code update(const std::string& path)
    {
        return call(path, Report::reportIfaceName, "Update");
    }

    boost::system::error_code deleteReport(const std::string& path)
    {
        return call(path, Report::deleteIfaceName, "Delete");
    }
};

TEST_F(TestReport, returnsId)
{
    EXPECT_THAT(sut->getId(), Eq(defaultParams().reportId()));
}

TEST_F(TestReport, verifyIfPropertiesHaveValidValue)
{
    EXPECT_THAT(getProperty<bool>(sut->getPath(), "Enabled"),
                Eq(defaultParams().enabled()));
    EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"),
                Eq(defaultParams().interval().count()));
    EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistency"), Eq(true));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        Eq(utils::transform(defaultParams().reportActions(), [](const auto v) {
            return utils::enumToString(v);
        })));
    EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"),
                Eq(utils::contains(defaultParams().reportActions(),
                                   ReportAction::emitsReadingsUpdate)));
    EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "AppendLimit"),
                Eq(defaultParams().appendLimit()));
    EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportingType"),
                Eq(utils::enumToString(defaultParams().reportingType())));
    EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportUpdates"),
                Eq(utils::enumToString(defaultParams().reportUpdates())));
    EXPECT_THAT(
        getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"),
        Eq(utils::contains(defaultParams().reportActions(),
                           ReportAction::logToMetricReportsCollection)));
    EXPECT_THAT(getProperty<ReadingParameters>(
                    sut->getPath(), "ReadingParametersFutureVersion"),
                Eq(toReadingParameters(defaultParams().metricParameters())));
    EXPECT_THAT(getProperty<std::string>(sut->getPath(), "Name"),
                Eq(defaultParams().reportName()));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"),
        Eq(std::vector<std::string>()));
}

TEST_F(TestReport, readingsAreInitialyEmpty)
{
    EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"),
                Eq(Readings{}));
}

TEST_F(TestReport, setReadingParametersWithNewParams)
{
    ReadingParameters newParams = toReadingParameters(
        std::vector<LabeledMetricParameters>{{LabeledMetricParameters{
            {LabeledSensorInfo{"Service",
                               "/xyz/openbmc_project/sensors/power/psu",
                               "NewMetadata123"}},
            OperationType::avg,
            "NewMetricId123",
            CollectionTimeScope::startup,
            CollectionDuration(250ms)}}});
    auto metrics = getMetricsFromReadingParams(newParams);

    EXPECT_CALL(*reportFactoryMock, updateMetrics(_, _, _))
        .WillOnce(SetArgReferee<0>(metrics));
    EXPECT_THAT(
        setProperty(sut->getPath(), "ReadingParametersFutureVersion", newParams)
            .value(),
        Eq(boost::system::errc::success));
    EXPECT_THAT(getProperty<ReadingParameters>(
                    sut->getPath(), "ReadingParametersFutureVersion"),
                Eq(newParams));
}

TEST_F(TestReport, setReportingTypeWithValidNewType)
{
    std::string newType = "Periodic";
    std::string currType = utils::enumToString(defaultParams().reportingType());

    EXPECT_THAT(newType, Ne(currType));
    EXPECT_THAT(setProperty(sut->getPath(), "ReportingType", newType).value(),
                Eq(boost::system::errc::success));
    EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportingType"),
                Eq(newType));
}

TEST_F(TestReport, setReportingTypeWithInvalidType)
{
    std::string newType = "Periodic_ABC";
    std::string prevType = utils::enumToString(defaultParams().reportingType());

    EXPECT_THAT(setProperty(sut->getPath(), "ReportingType", newType).value(),
                Eq(boost::system::errc::invalid_argument));
    EXPECT_THAT(getProperty<std::string>(sut->getPath(), "ReportingType"),
                Eq(prevType));
}

TEST_F(TestReport, setReportActionsWithValidNewActions)
{
    std::vector<std::string> newActions = {"EmitsReadingsUpdate"};
    std::vector<std::string> currActions =
        utils::transform(defaultParams().reportActions(),
                         [](const auto v) { return utils::enumToString(v); });

    EXPECT_THAT(newActions, Ne(currActions));
    EXPECT_THAT(
        setProperty(sut->getPath(), "ReportActions", newActions).value(),
        Eq(boost::system::errc::success));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        UnorderedElementsAre("EmitsReadingsUpdate",
                             "LogToMetricReportsCollection"));
}

TEST_F(TestReport, setReportActionsWithValidUnsortedActions)
{
    std::vector<std::string> newActions = {"LogToMetricReportsCollection",
                                           "EmitsReadingsUpdate"};
    std::vector<std::string> expectedActions = {"EmitsReadingsUpdate",
                                                "LogToMetricReportsCollection"};
    std::vector<std::string> currActions =
        utils::transform(defaultParams().reportActions(),
                         [](const auto v) { return utils::enumToString(v); });

    EXPECT_THAT(newActions, Ne(currActions));
    EXPECT_THAT(
        setProperty(sut->getPath(), "ReportActions", newActions).value(),
        Eq(boost::system::errc::success));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        Eq(expectedActions));
}

TEST_F(TestReport, setReportActionsWithEmptyActions)
{
    std::vector<std::string> newActions = {};
    std::vector<std::string> expectedActions = {"LogToMetricReportsCollection"};
    std::vector<std::string> currActions =
        utils::transform(defaultParams().reportActions(),
                         [](const auto v) { return utils::enumToString(v); });

    EXPECT_THAT(newActions, Ne(currActions));
    EXPECT_THAT(
        setProperty(sut->getPath(), "ReportActions", newActions).value(),
        Eq(boost::system::errc::success));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        Eq(expectedActions));
}

TEST_F(TestReport, setReportActionsWithInvalidActions)
{
    std::vector<std::string> invalidActions = {"EmitsReadingsUpdate_1"};
    EXPECT_THAT(
        setProperty(sut->getPath(), "ReportActions", invalidActions).value(),
        Eq(boost::system::errc::invalid_argument));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        Eq(utils::transform(defaultParams().reportActions(), [](const auto v) {
            return utils::enumToString(v);
        })));
}

TEST_F(TestReport, createReportWithEmptyActions)
{
    std::vector<std::string> expectedActions = {"LogToMetricReportsCollection"};

    sut = makeReport(ReportParams().reportId("TestId_1").reportActions({}));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        Eq(expectedActions));
}

TEST_F(TestReport, createReportWithValidUnsortedActions)
{
    std::vector<std::string> newActions = {"LogToMetricReportsCollection",
                                           "EmitsReadingsUpdate"};
    std::vector<std::string> expectedActions = {"EmitsReadingsUpdate",
                                                "LogToMetricReportsCollection"};

    sut = makeReport(
        ReportParams()
            .reportId("TestId_1")
            .reportActions(utils::transform(newActions, [](const auto& action) {
                return utils::toReportAction(action);
            })));
    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "ReportActions"),
        Eq(expectedActions));
}

TEST_F(TestReport, setEnabledWithNewValue)
{
    bool newValue = !defaultParams().enabled();
    EXPECT_THAT(setProperty(sut->getPath(), "Enabled", newValue).value(),
                Eq(boost::system::errc::success));
    EXPECT_THAT(getProperty<bool>(sut->getPath(), "Enabled"), Eq(newValue));
}

TEST_F(TestReport, setIntervalWithValidValue)
{
    uint64_t newValue = defaultParams().interval().count() + 1;
    EXPECT_THAT(setProperty(sut->getPath(), "Interval", newValue).value(),
                Eq(boost::system::errc::success));
    EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"),
                Eq(newValue));
}

TEST_F(
    TestReport,
    settingIntervalWithInvalidValueDoesNotChangePropertyAndReturnsInvalidArgument)
{
    uint64_t newValue = defaultParams().interval().count() - 1;
    EXPECT_THAT(setProperty(sut->getPath(), "Interval", newValue).value(),
                Eq(boost::system::errc::invalid_argument));
    EXPECT_THAT(getProperty<uint64_t>(sut->getPath(), "Interval"),
                Eq(defaultParams().interval().count()));
}

TEST_F(TestReport, settingEmitsReadingsUpdateHaveNoEffect)
{
    EXPECT_THAT(
        setProperty(sut->getPath(), "EmitsReadingsUpdate", true).value(),
        Eq(boost::system::errc::read_only_file_system));
    EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"),
                Eq(utils::contains(defaultParams().reportActions(),
                                   ReportAction::emitsReadingsUpdate)));
}

TEST_F(TestReport, settingLogToMetricReportCollectionHaveNoEffect)
{
    EXPECT_THAT(
        setProperty(sut->getPath(), "LogToMetricReportsCollection", true)
            .value(),
        Eq(boost::system::errc::read_only_file_system));
    EXPECT_THAT(
        getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"),
        Eq(utils::contains(defaultParams().reportActions(),
                           ReportAction::logToMetricReportsCollection)));
}

TEST_F(TestReport, settingPersistencyToFalseRemovesReportFromStorage)
{
    EXPECT_CALL(storageMock, store(_, _)).Times(0);
    EXPECT_CALL(storageMock, remove(to_file_path(sut->getId())))
        .Times(AtLeast(1));

    bool persistency = false;
    EXPECT_THAT(setProperty(sut->getPath(), "Persistency", persistency).value(),
                Eq(boost::system::errc::success));
    EXPECT_THAT(getProperty<bool>(sut->getPath(), "Persistency"),
                Eq(persistency));
}

TEST_F(TestReport, deleteReport)
{
    EXPECT_CALL(*reportManagerMock, removeReport(sut.get()));
    auto ec = deleteReport(sut->getPath());
    EXPECT_THAT(ec, Eq(boost::system::errc::success));
}

TEST_F(TestReport, deletingNonExistingReportReturnInvalidRequestDescriptor)
{
    auto ec = deleteReport(Report::reportDir + "NonExisting"s);
    EXPECT_THAT(ec.value(), Eq(EBADR));
}

TEST_F(TestReport, deleteReportExpectThatFileIsRemoveFromStorage)
{
    EXPECT_CALL(storageMock, store(_, _)).Times(0);
    EXPECT_CALL(storageMock, remove(to_file_path(sut->getId())))
        .Times(AtLeast(1));

    auto ec = deleteReport(sut->getPath());
    EXPECT_THAT(ec, Eq(boost::system::errc::success));
}

TEST_F(TestReport, updatesTriggerIdWhenTriggerIsAdded)
{
    utils::Messanger messanger(DbusEnvironment::getIoc());

    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger1", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger1", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger2", {"someOtherReport"}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist,
        "trigger3",
        {"someOtherReport", defaultParams().reportId()}});

    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"),
        UnorderedElementsAre("trigger1", "trigger3"));
}

TEST_F(TestReport, updatesTriggerIdWhenTriggerIsRemoved)
{
    utils::Messanger messanger(DbusEnvironment::getIoc());

    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger1", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger2", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger3", {defaultParams().reportId()}});

    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Removed, "trigger1", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Removed, "trigger2", {}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Removed, "trigger1", {defaultParams().reportId()}});

    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"),
        UnorderedElementsAre("trigger3"));
}

TEST_F(TestReport, updatesTriggerIdWhenTriggerIsModified)
{
    utils::Messanger messanger(DbusEnvironment::getIoc());

    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger1", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger2", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger3", {defaultParams().reportId()}});

    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger1", {defaultParams().reportId()}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger2", {}});
    messanger.send(messages::TriggerPresenceChangedInd{
        messages::Presence::Exist, "trigger3", {defaultParams().reportId()}});

    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"),
        UnorderedElementsAre("trigger1", "trigger3"));
}

class TestReportStore :
    public TestReport,
    public WithParamInterface<std::pair<std::string, nlohmann::json>>
{
    void SetUp() override
    {}
};

INSTANTIATE_TEST_SUITE_P(
    _, TestReportStore,
    Values(
        std::make_pair("Enabled"s, nlohmann::json(defaultParams().enabled())),
        std::make_pair("Version"s, nlohmann::json(6)),
        std::make_pair("Id"s, nlohmann::json(defaultParams().reportId())),
        std::make_pair("Name"s, nlohmann::json(defaultParams().reportName())),
        std::make_pair("ReportingType",
                       nlohmann::json(defaultParams().reportingType())),
        std::make_pair("ReportActions", nlohmann::json(utils::transform(
                                            defaultParams().reportActions(),
                                            [](const auto v) {
                                                return utils::toUnderlying(v);
                                            }))),
        std::make_pair("Interval",
                       nlohmann::json(defaultParams().interval().count())),
        std::make_pair("AppendLimit",
                       nlohmann::json(ReportParams().appendLimit())),
        std::make_pair(
            "ReadingParameters",
            nlohmann::json(
                {{{tstring::SensorPath::str(),
                   {{{tstring::Service::str(), "Service"},
                     {tstring::Path::str(),
                      "/xyz/openbmc_project/sensors/power/p1"},
                     {tstring::Metadata::str(), "metadata1"}}}},
                  {tstring::OperationType::str(), OperationType::avg},
                  {tstring::Id::str(), "MetricId1"},
                  {tstring::CollectionTimeScope::str(),
                   CollectionTimeScope::point},
                  {tstring::CollectionDuration::str(), 0}},
                 {{tstring::SensorPath::str(),
                   {{{tstring::Service::str(), "Service"},
                     {tstring::Path::str(),
                      "/xyz/openbmc_project/sensors/power/p2"},
                     {tstring::Metadata::str(), "metadata2"}}}},
                  {tstring::OperationType::str(), OperationType::avg},
                  {tstring::Id::str(), "MetricId2"},
                  {tstring::CollectionTimeScope::str(),
                   CollectionTimeScope::point},
                  {tstring::CollectionDuration::str(), 0}}}))));

TEST_P(TestReportStore, settingPersistencyToTrueStoresReport)
{
    sut = makeReport(defaultParams());

    {
        InSequence seq;
        EXPECT_CALL(storageMock, remove(to_file_path(sut->getId())));
        EXPECT_CALL(checkPoint, Call());
        EXPECT_CALL(storageMock, store(to_file_path(sut->getId()), _));
    }

    setProperty(sut->getPath(), "Persistency", false);
    checkPoint.Call();
    setProperty(sut->getPath(), "Persistency", true);

    const auto& [key, value] = GetParam();

    ASSERT_THAT(storedConfiguration.at(key), Eq(value));
}

TEST_P(TestReportStore, reportIsSavedToStorageAfterCreated)
{
    EXPECT_CALL(storageMock,
                store(to_file_path(defaultParams().reportId()), _));

    sut = makeReport(defaultParams());

    const auto& [key, value] = GetParam();

    ASSERT_THAT(storedConfiguration.at(key), Eq(value));
}

class TestReportValidNames :
    public TestReport,
    public WithParamInterface<ReportParams>
{
  public:
    void SetUp() override
    {}
};

INSTANTIATE_TEST_SUITE_P(
    ValidNames, TestReportValidNames,
    Values(defaultParams().reportName("Valid_1"),
           defaultParams().reportName("Valid_1/Valid_2"),
           defaultParams().reportName("Valid_1/Valid_2/Valid_3")));

TEST_P(TestReportValidNames, reportCtorDoesNotThrowOnValidName)
{
    EXPECT_NO_THROW(makeReport(GetParam()));
}

class TestReportInvalidIds :
    public TestReport,
    public WithParamInterface<ReportParams>
{
  public:
    void SetUp() override
    {}
};

INSTANTIATE_TEST_SUITE_P(InvalidNames, TestReportInvalidIds,
                         Values(defaultParams().reportId("/"),
                                defaultParams().reportId("/Invalid"),
                                defaultParams().reportId("Invalid/"),
                                defaultParams().reportId("Invalid/Invalid/"),
                                defaultParams().reportId("Invalid?")));

TEST_P(TestReportInvalidIds, failsToCreateReportWithInvalidName)
{
    EXPECT_CALL(storageMock, store).Times(0);

    EXPECT_THROW(makeReport(GetParam()), sdbusplus::exception::SdBusError);
}

class TestReportAllReportTypes :
    public TestReport,
    public WithParamInterface<ReportParams>
{
  public:
    void SetUp() override
    {
        sut = makeReport(GetParam());
    }
};

INSTANTIATE_TEST_SUITE_P(
    _, TestReportAllReportTypes,
    Values(defaultParams().reportingType(ReportingType::onRequest),
           defaultParams().reportingType(ReportingType::onChange),
           defaultParams().reportingType(ReportingType::periodic)));

TEST_P(TestReportAllReportTypes, returnPropertValueOfReportType)
{
    EXPECT_THAT(utils::toReportingType(
                    getProperty<std::string>(sut->getPath(), "ReportingType")),
                Eq(GetParam().reportingType()));
}

TEST_P(TestReportAllReportTypes, readingsAreUpdated)
{
    clockFake.system.advance(10ms);

    messanger.send(messages::UpdateReportInd{{sut->getId()}});
    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms));
}

TEST_P(TestReportAllReportTypes, readingsAreNotUpdatedWhenReportIsDisabled)
{
    clockFake.system.advance(10ms);

    setProperty(sut->getPath(), "Enabled", false);
    messanger.send(messages::UpdateReportInd{{sut->getId()}});
    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(Milliseconds{timestamp}, Eq(0ms));
}

TEST_P(TestReportAllReportTypes, readingsAreNotUpdatedWhenReportIdDiffers)
{
    clockFake.system.advance(10ms);

    messanger.send(messages::UpdateReportInd{{sut->getId() + "x"s}});
    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(Milliseconds{timestamp}, Eq(0ms));
}

class TestReportOnRequestType : public TestReport
{
    void SetUp() override
    {
        sut =
            makeReport(defaultParams().reportingType(ReportingType::onRequest));
    }
};

TEST_F(TestReportOnRequestType, updatesReadingTimestamp)
{
    clockFake.system.advance(10ms);

    ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success));

    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms));
}

TEST_F(TestReportOnRequestType, updatesReadingWhenUpdateIsCalled)
{
    ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success));

    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(readings,
                ElementsAre(std::make_tuple("a"s, "b"s, 17.1, 114u),
                            std::make_tuple("aa"s, "bb"s, 42.0, 74u)));
}

class TestReportNonOnRequestType :
    public TestReport,
    public WithParamInterface<ReportParams>
{
    void SetUp() override
    {
        sut = makeReport(GetParam());
    }
};

INSTANTIATE_TEST_SUITE_P(
    _, TestReportNonOnRequestType,
    Values(defaultParams().reportingType(ReportingType::periodic),
           defaultParams().reportingType(ReportingType::onChange)));

TEST_P(TestReportNonOnRequestType, readingsAreNotUpdateOnUpdateCall)
{
    ASSERT_THAT(update(sut->getPath()), Eq(boost::system::errc::success));

    EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"),
                Eq(Readings{}));
}

class TestReportNonPeriodicReport :
    public TestReport,
    public WithParamInterface<ReportParams>
{
  public:
    void SetUp() override
    {
        sut = makeReport(GetParam());
    }
};

INSTANTIATE_TEST_SUITE_P(
    _, TestReportNonPeriodicReport,
    Values(defaultParams().reportingType(ReportingType::onRequest),
           defaultParams().reportingType(ReportingType::onChange)));

TEST_P(TestReportNonPeriodicReport, readingsAreNotUpdatedAfterIntervalExpires)
{
    DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms);

    EXPECT_THAT(getProperty<Readings>(sut->getPath(), "Readings"),
                Eq(Readings{}));
}

class TestReportPeriodicReport : public TestReport
{
    void SetUp() override
    {
        sut =
            makeReport(defaultParams().reportingType(ReportingType::periodic));
    }
};

TEST_F(TestReportPeriodicReport, readingTimestampIsUpdatedAfterIntervalExpires)
{
    clockFake.system.advance(10ms);
    DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms);

    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(Milliseconds{timestamp}, Eq(systemTimestamp + 10ms));
}

TEST_F(TestReportPeriodicReport, readingsAreUpdatedAfterIntervalExpires)
{
    DbusEnvironment::sleepFor(ReportManager::minInterval + 1ms);

    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");

    EXPECT_THAT(readings,
                ElementsAre(std::make_tuple("a"s, "b"s, 17.1, 114u),
                            std::make_tuple("aa"s, "bb"s, 42.0, 74u)));
}

struct ReportUpdatesReportParams
{
    ReportParams reportParams;
    std::vector<ReadingData> expectedReadings;
    bool expectedEnabled;
};

class TestReportWithReportUpdatesAndLimit :
    public TestReport,
    public WithParamInterface<ReportUpdatesReportParams>
{
    void SetUp() override
    {
        sut = makeReport(ReportParams(GetParam().reportParams)
                             .reportingType(ReportingType::periodic)
                             .interval(std::chrono::hours(1000)));
    }
};

INSTANTIATE_TEST_SUITE_P(
    _, TestReportWithReportUpdatesAndLimit,
    Values(
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendWrapsWhenFull)
                .appendLimit(5),
            std::vector<ReadingData>{{std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                                      std::make_tuple("a"s, "b"s, 17.1, 114u),
                                      std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                                      std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                                      std::make_tuple("a"s, "b"s, 17.1, 114u)}},
            true},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendWrapsWhenFull)
                .appendLimit(4),
            std::vector<ReadingData>{
                {std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                 std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u)}},
            true},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendWrapsWhenFull)
                .appendLimit(0),
            std::vector<ReadingData>{}, true},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendStopsWhenFull)
                .appendLimit(10),
            std::vector<ReadingData>{
                {std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                 std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                 std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                 std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u)}},
            true},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendStopsWhenFull)
                .appendLimit(5),
            std::vector<ReadingData>{{std::make_tuple("a"s, "b"s, 17.1, 114u),
                                      std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                                      std::make_tuple("a"s, "b"s, 17.1, 114u),
                                      std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                                      std::make_tuple("a"s, "b"s, 17.1, 114u)}},
            false},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendStopsWhenFull)
                .appendLimit(4),
            std::vector<ReadingData>{
                {std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u),
                 std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u)}},
            false},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::appendStopsWhenFull)
                .appendLimit(0),
            std::vector<ReadingData>{}, false},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::overwrite)
                .appendLimit(500),
            std::vector<ReadingData>{
                {std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u)}},
            true},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::overwrite)
                .appendLimit(1),
            std::vector<ReadingData>{
                {std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u)}},
            true},
        ReportUpdatesReportParams{
            defaultParams()
                .reportUpdates(ReportUpdates::overwrite)
                .appendLimit(0),
            std::vector<ReadingData>{
                {std::make_tuple("a"s, "b"s, 17.1, 114u),
                 std::make_tuple("aa"s, "bb"s, 42.0, 74u)}},
            true}));

TEST_P(TestReportWithReportUpdatesAndLimit,
       readingsAreUpdatedAfterIntervalExpires)
{
    for (int i = 0; i < 4; i++)
    {
        messanger.send(messages::UpdateReportInd{{sut->getId()}});
    }

    const auto [timestamp, readings] =
        getProperty<Readings>(sut->getPath(), "Readings");
    const auto enabled = getProperty<bool>(sut->getPath(), "Enabled");

    EXPECT_THAT(readings, ElementsAreArray(GetParam().expectedReadings));
    EXPECT_EQ(enabled, GetParam().expectedEnabled);
}

class TestReportInitialization : public TestReport
{
  public:
    void SetUp() override
    {
        initMetricMocks(defaultParams().metricParameters());
    }

    void monitorProc(sdbusplus::message::message& msg)
    {
        std::string iface;
        std::vector<std::pair<std::string, std::variant<Readings>>>
            changed_properties;
        std::vector<std::string> invalidated_properties;

        msg.read(iface, changed_properties, invalidated_properties);

        if (iface == Report::reportIfaceName)
        {
            for (const auto& [name, value] : changed_properties)
            {
                if (name == "Readings")
                {
                    readingsUpdated.Call();
                }
            }
        }
    }

    void makeMonitor()
    {
        monitor = std::make_unique<sdbusplus::bus::match_t>(
            *DbusEnvironment::getBus(),
            sdbusplus::bus::match::rules::propertiesChanged(
                sut->getPath(), Report::reportIfaceName),
            [this](auto& msg) { monitorProc(msg); });
    }

    std::unique_ptr<sdbusplus::bus::match_t> monitor;
    MockFunction<void()> readingsUpdated;
};

TEST_F(TestReportInitialization,
       registersForMetricUpdatesWhenOnChangeReportCreated)
{
    std::vector<const interfaces::MetricListener*> args;
    for (auto& metric : metricMocks)
    {
        EXPECT_CALL(*metric, registerForUpdates(_))
            .WillOnce(Invoke([&args](const interfaces::MetricListener& report) {
                args.emplace_back(&report);
            }));
        ;
    }

    sut = makeReport(defaultParams().reportingType(ReportingType::onChange));

    EXPECT_THAT(args, SizeIs(metricMocks.size()));
    for (const auto* reportPtr : args)
    {
        EXPECT_THAT(reportPtr, Eq(sut.get()));
    }
}

TEST_F(TestReportInitialization,
       deregistersForMetricUpdatesWhenOnChangeReportDestroyed)
{
    sut = makeReport(defaultParams().reportingType(ReportingType::onChange));

    for (auto& metric : metricMocks)
    {
        EXPECT_CALL(*metric,
                    unregisterFromUpdates(Ref(
                        static_cast<interfaces::MetricListener&>(*sut.get()))));
    }

    sut = nullptr;
}

TEST_F(TestReportInitialization,
       metricsAreInitializedWhenEnabledReportConstructed)
{
    for (auto& metric : metricMocks)
    {
        EXPECT_CALL(*metric, initialize());
    }
    sut = makeReport(defaultParams().enabled(true));
}

TEST_F(TestReportInitialization,
       metricsAreNotInitializedWhenDisabledReportConstructed)
{
    for (auto& metric : metricMocks)
    {
        EXPECT_CALL(*metric, initialize()).Times(0);
    }
    sut = makeReport(defaultParams().enabled(false));
}

TEST_F(TestReportInitialization,
       emitReadingsUpdateIsTrueReadingsPropertiesChangedSingalEmits)
{
    EXPECT_CALL(readingsUpdated, Call())
        .WillOnce(
            InvokeWithoutArgs(DbusEnvironment::setPromise("readingsUpdated")));

    const auto elapsed = DbusEnvironment::measureTime([this] {
        sut =
            makeReport(defaultParams()
                           .reportingType(ReportingType::periodic)
                           .reportActions({ReportAction::emitsReadingsUpdate}));
        makeMonitor();
        EXPECT_TRUE(DbusEnvironment::waitForFuture("readingsUpdated"));
    });

    EXPECT_THAT(elapsed, AllOf(Ge(defaultParams().interval()),
                               Lt(defaultParams().interval() * 2)));
}

TEST_F(TestReportInitialization,
       emitReadingsUpdateIsFalseReadingsPropertiesChangesSigalDoesNotEmits)
{
    EXPECT_CALL(readingsUpdated, Call()).Times(0);

    sut = makeReport(defaultParams()
                         .reportingType(ReportingType::periodic)
                         .reportActions({}));
    makeMonitor();
    DbusEnvironment::sleepFor(defaultParams().interval() * 2);
}

TEST_F(TestReportInitialization, appendLimitDeducedProperly)
{
    sut = makeReport(
        defaultParams().appendLimit(std::numeric_limits<uint64_t>::max()));
    auto appendLimit = getProperty<uint64_t>(sut->getPath(), "AppendLimit");
    EXPECT_EQ(appendLimit, 2ull);
}

TEST_F(TestReportInitialization, appendLimitSetToUintMaxIsStoredCorrectly)
{
    sut = makeReport(
        ReportParams().appendLimit(std::numeric_limits<uint64_t>::max()));

    ASSERT_THAT(storedConfiguration.at("AppendLimit"),
                Eq(std::numeric_limits<uint64_t>::max()));
}

TEST_F(TestReportInitialization, triggerIdsPropertyIsInitialzed)
{
    for (const auto& triggerId : {"trigger1", "trigger2"})
    {
        messanger.on_receive<messages::CollectTriggerIdReq>(
            [this, triggerId](const auto& msg) {
                messanger.send(messages::CollectTriggerIdResp{triggerId});
            });
    }

    sut = makeReport(ReportParams());

    EXPECT_THAT(
        getProperty<std::vector<std::string>>(sut->getPath(), "TriggerIds"),
        UnorderedElementsAre("trigger1", "trigger2"));
}

TEST_F(TestReportInitialization,
       metricValuesAreNotStoredForReportUpdatesDifferentThanAppendStopsWhenFull)
{
    sut = makeReport(ReportParams()
                         .reportingType(ReportingType::periodic)
                         .interval(1h)
                         .reportUpdates(ReportUpdates::appendWrapsWhenFull)
                         .readings(Readings{{}, {{}}}));

    ASSERT_THAT(storedConfiguration.find("MetricValues"),
                Eq(storedConfiguration.end()));
}

TEST_F(TestReportInitialization, metricValuesAreNotStoredForOnRequestReport)
{
    sut = makeReport(ReportParams()
                         .reportingType(ReportingType::onRequest)
                         .reportUpdates(ReportUpdates::appendStopsWhenFull)
                         .readings(Readings{{}, {{}}}));

    ASSERT_THAT(storedConfiguration.find("MetricValues"),
                Eq(storedConfiguration.end()));
}

TEST_F(TestReportInitialization,
       metricValuesAreStoredForNonOnRequestReportWithAppendStopsWhenFull)
{
    const auto readings = Readings{{}, {{}}};

    sut = makeReport(ReportParams()
                         .reportingType(ReportingType::periodic)
                         .interval(1h)
                         .reportUpdates(ReportUpdates::appendStopsWhenFull)
                         .readings(readings));

    ASSERT_THAT(storedConfiguration.at("MetricValues").get<LabeledReadings>(),
                Eq(utils::toLabeledReadings(readings)));
}

class TestReportInitializationOnChangeReport : public TestReportInitialization
{
  public:
    void SetUp() override
    {
        initMetricMocks(params.metricParameters());
    }

    ReportParams params = defaultOnChangeParams();
};

TEST_F(TestReportInitializationOnChangeReport,
       doesntUpdateReadingsWhenNotRequired)
{
    EXPECT_CALL(*metricMocks[0], updateReadings(_)).Times(0);

    ON_CALL(*metricMocks[0], isTimerRequired()).WillByDefault(Return(false));

    sut = makeReport(params);

    DbusEnvironment::sleepFor(500ms);
}

TEST_F(TestReportInitializationOnChangeReport, updatesReadingsWhenRequired)
{
    EXPECT_CALL(*metricMocks[0], updateReadings(_))
        .WillOnce(Return())
        .WillOnce(
            InvokeWithoutArgs(DbusEnvironment::setPromise("readingsUpdated")))
        .WillRepeatedly(Return());

    ON_CALL(*metricMocks[0], isTimerRequired()).WillByDefault(Return(true));

    sut = makeReport(params);

    DbusEnvironment::waitForFuture("readingsUpdated");
}
