#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_numeric_division(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 = CastToNumber(ApplyInternal(values[0], data));
        if (HasError()) return Json{};
        const Json rhs = CastToNumber(ApplyInternal(values[1], data));
        if (HasError()) return Json{};
        return MakeNumber(ToDouble(lhs) / ToDouble(rhs));
    }
}
