#ifndef JSON_LOGIC_CPP_TEST_FIXTURE_H
#define JSON_LOGIC_CPP_TEST_FIXTURE_H

#include <cstddef>
#include <stdexcept>
#include <vector>

#include "gtest/gtest.h"

#include "JsonLogic.h"

using namespace json_logic;

inline Json operator""_json(const char* text, std::size_t size)
{
	Json result;
	const auto error = ArduinoJson::deserializeJson(result, text, size);
	if (error) throw std::runtime_error(error.c_str());
	return result;
}

inline bool JsonEquals(JsonView actual, JsonView expected)
{
	return actual == expected;
}

template <typename T>
bool JsonEquals(JsonView actual, const std::vector<T>& expected)
{
	Json expected_json;
	auto array = expected_json.to<ArduinoJson::JsonArray>();
	for (const auto& value : expected) array.add(static_cast<T>(value));
	return actual == expected_json.as<ArduinoJson::JsonVariantConst>();
}

class JsonLogicTest : public testing::Test
{
protected:
	IJsonLogic* json_logic_;

	void SetUp() override
	{
		json_logic_ = JsonLogic::GetInstance();
	}
};

#endif //JSON_LOGIC_CPP_TEST_FIXTURE_H
