#include "association_manager.hpp"

#include <filesystem>
#include <fstream>

#include <gtest/gtest.h>

using namespace phosphor::inventory::manager::associations;
namespace fs = std::filesystem;

static const auto goodJson = R"(
[
    {
        "path": "system/PS0",
        "endpoints":
        [
            {
                "types":
                {
                    "rType": "inventory",
                    "fType": "sensors"
                },
                "paths":
                [
                    "power/ps0_input_power",
                    "voltage/ps0_input_voltage",
                    "current/ps0_output_current",
                    "voltage/ps0_output_voltage"
                ]
            },
            {
                "types":
                {
                    "rType": "inventory",
                    "fType": "fans"
                },
                "paths":
                [
                    "fan_tach/ps0_fan"
                ]
            }
        ]
    },
    {
        "path": "system/fan42",
        "endpoints":
        [
            {
                "types":
                {
                    "rType": "inventory",
                    "fType": "sensors"
                },
                "paths":
                [
                    "fan_tach/fan42"
                ]
            },
            {
                "types":
                {
                    "rType": "inventory",
                    "fType": "led"
                },
                "paths":
                [
                    "led/fan42"
                ]
            }
        ]
    }
])";

// Malformed JSON
static const auto badJson0 = R"(
    "hello": world
})";

// Uses 'blah' instead of 'paths'
static const auto badJson1 = R"(
[
    {
        "blah": "system/PS0",
        "endpoints":
        [
            {
                "types":
                {
                    "fType": "inventory",
                    "rType": "sensors"
                },
                "paths":
                [
                    "ps0_input_power",
                ]
            }
        ]
    }
])";

// Uses 'blah' instead of 'rType'
static const auto badJson2 = R"(
[
    {
        "paths": "system/PS0",
        "endpoints":
        [
            {
                "types":
                {
                    "blah": "inventory",
                    "fType": "sensors"
                },
                "paths":
                [
                    "ps0_input_power",
                ]
            }
        ]
    }
])";

// Missing the endpoints/paths array
static const auto badJson3 = R"(
[
    {
        "paths": "system/PS0",
        "endpoints":
        [
            {
                "types":
                {
                    "rType": "inventory",
                    "fType": "sensors"
                }
            }
        ]
    }
])";

class AssocsTest : public ::testing::Test
{
  protected:
    AssocsTest() : ::testing::Test(), bus(sdbusplus::bus::new_default()) {}

    fs::path jsonDir;
    sdbusplus::bus_t bus;

    virtual void SetUp()
    {
        char dir[] = {"assocTestXXXXXX"};
        jsonDir = mkdtemp(dir);
    }

    virtual void TearDown()
    {
        fs::remove_all(jsonDir);
    }

    std::string writeFile(const char* data)
    {
        fs::path path = jsonDir / "associations.json";

        std::ofstream f{path};
        f << data;
        f.close();

        return path;
    }
};

TEST_F(AssocsTest, TEST_NO_JSON)
{
    try
    {
        Manager m{bus};
        EXPECT_TRUE(false);
    }
    catch (const std::exception& e)
    {}
}

TEST_F(AssocsTest, TEST_GOOD_JSON)
{
    auto path = writeFile(goodJson);
    Manager m(bus, path);

    const auto& a = m.getAssociationsConfig();
    EXPECT_EQ(a.size(), 2);

    {
        auto x = a.find("/xyz/openbmc_project/inventory/system/PS0");
        EXPECT_NE(x, a.end());

        auto& endpoints = x->second;
        EXPECT_EQ(endpoints.size(), 2);

        {
            auto& types = std::get<0>(endpoints[0]);
            EXPECT_EQ(std::get<0>(types), "sensors");
            EXPECT_EQ(std::get<1>(types), "inventory");

            auto& paths = std::get<1>(endpoints[0]);
            EXPECT_EQ(paths.size(), 4);
        }
        {
            auto& types = std::get<0>(endpoints[1]);
            EXPECT_EQ(std::get<0>(types), "fans");
            EXPECT_EQ(std::get<1>(types), "inventory");

            auto& paths = std::get<1>(endpoints[1]);
            EXPECT_EQ(paths.size(), 1);
        }
    }
    {
        auto x = a.find("/xyz/openbmc_project/inventory/system/fan42");
        EXPECT_NE(x, a.end());

        auto& endpoints = x->second;
        EXPECT_EQ(endpoints.size(), 2);

        {
            auto& types = std::get<0>(endpoints[0]);
            EXPECT_EQ(std::get<0>(types), "sensors");
            EXPECT_EQ(std::get<1>(types), "inventory");

            auto& paths = std::get<1>(endpoints[0]);
            EXPECT_EQ(paths.size(), 1);
        }
        {
            auto& types = std::get<0>(endpoints[1]);
            EXPECT_EQ(std::get<0>(types), "led");
            EXPECT_EQ(std::get<1>(types), "inventory");

            auto& paths = std::get<1>(endpoints[1]);
            EXPECT_EQ(paths.size(), 1);
        }
    }
}

TEST_F(AssocsTest, TEST_BAD_JSON0)
{
    auto path = writeFile(badJson0);

    try
    {
        Manager m(bus, path);

        EXPECT_TRUE(false);
    }
    catch (const std::exception& e)
    {}
}

TEST_F(AssocsTest, TEST_BAD_JSON1)
{
    auto path = writeFile(badJson1);

    try
    {
        Manager m(bus, path);

        EXPECT_TRUE(false);
    }
    catch (const std::exception& e)
    {}
}

TEST_F(AssocsTest, TEST_BAD_JSON2)
{
    auto path = writeFile(badJson2);

    try
    {
        Manager m(bus, path);

        EXPECT_TRUE(false);
    }
    catch (const std::exception& e)
    {}
}

TEST_F(AssocsTest, TEST_BAD_JSON3)
{
    auto path = writeFile(badJson3);

    try
    {
        Manager m(bus, path);

        EXPECT_TRUE(false);
    }
    catch (const std::exception& e)
    {}
}
