#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_numeric_addition(JsonArrayView values, JsonView data) const
    {
        if (values.size() == 0)
            return Fail(__FUNCTION__, "Expected 1 or more arguments, but received 0");
        if (values.size() == 1) return CastToNumber(ApplyInternal(values[0], data));

        double result = 0;
        for (JsonView value : values)
        {
            const Json number = CastToNumber(ApplyInternal(value, data));
            if (HasError()) return Json{};
            result += ToDouble(number);
        }
        return MakeNumber(result);
    }
}
