//
// Created by Ht on 2022/9/6.
//

#ifndef INC_1_LIBDEVCPP_QGAVARFUNCS_H
#define INC_1_LIBDEVCPP_QGAVARFUNCS_H

#include <qlibc/qlibc.h>

namespace jedge {
    //用户自定义的变量响应函数接口
    //对varKey，在msg中查找变量或函数，以ret未返回值，
    using GaVarFinder = std::function<bool(Json::Value& ret,const std::string& varKey, const qlibc::QData& msg, bool isFunc)>;
    using GaUserDefFunction = std::function<bool(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg)>;
    using GaUserDefFunctionVar = std::function<bool(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder)>;

    //标准系统函数
    bool hexStrToNum(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool toStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool intToHexStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool longToHexStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool byteLen(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool replaceAll(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool randomHexStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool randomIntStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool reversBigSmallEnd(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool expandHexString(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool tableTrans(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool tableKeyTrans(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool parseJson(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool subStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool splitStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    //计算一个字符串的长度，如果值是其它值，则转化为字符串后计算
    // ${@strLen:12345} == 5
    bool strLen(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool subBetween(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool subBefore(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool subAfter(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool toLower(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool toUpper(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool Base64EncodeFromHex(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool Base64DecodeToHex(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool isMember(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    // ${@list2PropArray:a,b} 将list中的对象元素值进行简化
    // list2ObjArray:arr,a,b... :: arr [{a:v1a,b:v2a,...},{a:v2a,b:v2b,...}...] -> [{a:v1a,b:v2a},{a:v2a,b:v2b}]
    bool list2ObjArray(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    //${@list2PropArray: <jsonArrayKey>,<propKey1>,...} 组成一个新的只包含值的JsonArray数组
    // list2ObjArray:arr,a... :: arr [{a:v1a,b:v2a,...},{a:v2a,b:v2b,...}...] -> [v1a,v2a,...]
    bool list2PropArray(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool orderAvailable(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool nullIfFalse(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool list2ObjectMap(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool obj2PropArray(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool strArr2String(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool strArray2ObjArray(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool listAdd(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool listRemove(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool decNumberPlus(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool decNumberMinus(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);
    bool checkField(Json::Value &ret, QStringList &funcParams, const qlibc::QData &msg, GaVarFinder *finder);
    //获得当前系统时间 ms ${@sysTimeMs}
    bool sysTimeMs(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool reversStr(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);

    bool sizeOf(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg, GaVarFinder* finder);


    bool firstIfTrue(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);
    bool MD5(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);
    bool dec(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);
    bool inc(Json::Value& ret, QStringList& funcParams, const qlibc::QData& msg);
}


#endif //INC_1_LIBDEVCPP_QGAVARFUNCS_H
