#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_data_var(JsonArrayView values, JsonView data) const
    {
        if (values.size() == 0 || values.size() > 2)
            return Fail(__FUNCTION__, "Expected 1 or 2 arguments, but received " +
                                          std::to_string(values.size()));

        Json result;
        if (TryResolveVariable(values[0], data, result)) return result;
        if (values.size() == 2) return ApplyInternal(values[1], data);

        return Fail(__FUNCTION__, "Data object does not contain specified member");
    }
}
