#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_numeric_max(JsonArrayView values, JsonView data) const
    {
        if (values.size() == 0) return Fail(__FUNCTION__, "Expected at least 1 argument");

        Json result = CastToNumber(ApplyInternal(values[0], data));
        if (HasError()) return Json{};
        for (std::size_t i = 1; i < values.size(); ++i)
        {
            Json value = CastToNumber(ApplyInternal(values[i], data));
            if (HasError()) return Json{};
            if (ToDouble(value) > ToDouble(result)) result = value;
        }
        return result;
    }
}
