#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_logic_abstract_equal(JsonArrayView values, JsonView data) const
    {
        if (values.size() != 2)
            return Fail(__FUNCTION__, "Expected 2 arguments, but received " +
                                          std::to_string(values.size()));
        const Json lhs = ApplyInternal(values[0], data);
        if (HasError()) return Json{};
        const Json rhs = ApplyInternal(values[1], data);
        if (HasError()) return Json{};
        return MakeBoolean(AbstractEqual(lhs, rhs));
    }

    Json JsonLogic::operation_logic_strict_equal(JsonArrayView values, JsonView data) const
    {
        if (values.size() != 2)
            return Fail(__FUNCTION__, "Expected 2 arguments, but received " +
                                          std::to_string(values.size()));
        const Json lhs = ApplyInternal(values[0], data);
        if (HasError()) return Json{};
        const Json rhs = ApplyInternal(values[1], data);
        if (HasError()) return Json{};
        return MakeBoolean(StrictEqual(lhs, rhs));
    }
}
