#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_numeric_lt(JsonArrayView values, JsonView data) const
    {
        if (values.size() < 2 || values.size() > 3)
            return Fail(__FUNCTION__, "Expected 2 or 3 arguments, but received " +
                                          std::to_string(values.size()));
        const Json lhs = CastToNumber(ApplyInternal(values[0], data));
        if (HasError()) return Json{};
        const Json middle = CastToNumber(ApplyInternal(values[1], data));
        if (HasError()) return Json{};
        if (values.size() == 2) return MakeBoolean(ToDouble(lhs) < ToDouble(middle));

        const Json rhs = CastToNumber(ApplyInternal(values[2], data));
        if (HasError()) return Json{};
        return MakeBoolean(ToDouble(lhs) < ToDouble(middle) && ToDouble(middle) < ToDouble(rhs));
    }
}
