//
// Created by Ht on 2019/12/25.
//

#ifndef LIBGOING_JCARGNODE_H
#define LIBGOING_JCARGNODE_H

#include <jebase/config.h>

#include "JCBaseNode.h"

namespace qlibc {

    static const char cmd_seperator = ';';
    static const char cmd_quoter = '"';
    static const char* cmd_seperator_s = ";";
    static const char* cmd_quoter_s = "\"";
    static const char cmd_sub_quoter = '\'';
    static const char* cmd_sub_quoter_s = "'";

    class JE_API JCArgNode :
        public JCBaseNode {

    public:
        std::string  getParam(int i, const std::string& defVal = "") const;

        Json::Value* getParamValue(int i) ;

        inline Json::Value getParamValue(int i, const Json::Value& defVal) {
            auto* v = getParamValue(i);
            return v!=nullptr?(*v):defVal;
        }

        int getParamAsInt(int index, int defVal = -1) const ;

        int getParamCount() const;

        bool getParamAsBool(int index) const ;

        //index should be end with -1
        int removeParamAt(std::vector<Json::Value>* delValue, int index, int cnt = 1);

        int insertParamAt(int index, ...);

        int appendParam(const char* first, ...);

        bool checkParamValid(int paramCnt, ...) const;

        std::string getOriginCommandStr() const;

        std::string toCommandStr(char quoteChar = cmd_sub_quoter, bool hardSep = false) const;

        Json::Value& getParamValues();

        Json::Value& getParamValuesAsConst() const;
    };

#define CHK_PARAM(var, cnt, ...) \
    ((var).checkParamValid(cnt, ##__VA_ARGS__, nullptr))

#define INSERT_PARAM(var, index, ...) \
    ((var).insertParamAt(index, ##__VA_ARGS__, nullptr))

#define APPEND_PARAM(var, first, ...) \
    ((var).appendParam(first, ##__VA_ARGS__, nullptr))
}

#endif //LIBGOING_JCARGNODE_H
