#include "JsonLogic.h"

namespace json_logic
{
    Json JsonLogic::operation_string_cat(JsonArrayView values, JsonView data) const
    {
        if (values.size() < 2)
            return Fail(__FUNCTION__, "Expected 2 or more arguments, but received " +
                                          std::to_string(values.size()));

        std::string result;
        for (JsonView value : values)
        {
            const Json applied = ApplyInternal(value, data);
            if (HasError()) return Json{};
            if (!applied.is<const char*>())
                return Fail(__FUNCTION__, "All arguments must be strings");
            result += applied.as<const char*>();
        }
        return MakeString(result);
    }
}
