package kv;

import common.Constant;
import common.Resp;
import config.Config;
import exception.ZXChainException;
import util.HttpUtil;
import util.Tools;
import util.ZxlSDKUtil;

public class KvQuery {
    String kvKey;
    boolean isNeedValue;

    public KvQuery() {
    }

    public KvQuery(String kvKey, boolean isNeedValue) {
        this.kvKey = kvKey;
        this.isNeedValue = isNeedValue;
    }

    public KvQueryResp query() throws Exception {
        Resp resp = HttpUtil.apiGetJsonX(Config.baseUrl + "/api/v1/kv/query", Tools.getJson(this), ZxlSDKUtil.generateApiSign());
        if (resp.getRetCode() != Constant.ZXL_OK) {
            throw new ZXChainException(resp.getRetMsg());
        }

        return resp.getData(KvQueryResp.class);
    }

    public String getKvKey() {
        return kvKey;
    }

    public void setKvKey(String kvKey) {
        this.kvKey = kvKey;
    }

    public boolean isNeedValue() {
        return isNeedValue;
    }

    public void setNeedValue(boolean needValue) {
        isNeedValue = needValue;
    }
}
