package nft.point;

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

public class Apply {
    String applyerAddr;
    String platformPubKey;
    long count;
    String operateId;
    String platformSignature;

    public Apply() {
    }

    public Apply(String applyerAddr, long count, String operateId) {
        this.applyerAddr = applyerAddr;
        this.count = count;
        this.operateId = operateId;
    }

    public String apply() throws Exception {
        this.setPlatformPubKey(Config.platformPubKey);
        String signData = Tools.getSignData(
                this.platformPubKey,
                this.applyerAddr,
                "apply_point",
                this.count,
                this.operateId);
        this.setPlatformSignature(ZxlSDKUtil.signByPriKey(Config.platformPrivateKey, signData));

        Resp resp = HttpUtil.apiPostJsonX(Config.baseUrl + "/api/v1/nft/point/apply", Tools.getJson(this), ZxlSDKUtil.generateApiSign());
        if (resp.getRetCode() != Constant.ZXL_OK) {
            throw new ZXChainException(resp.getRetMsg());
        }

        return resp.getData().getString("taskId");
    }

    public String getApplyerAddr() {
        return applyerAddr;
    }

    public void setApplyerAddr(String applyerAddr) {
        this.applyerAddr = applyerAddr;
    }

    public String getPlatformPubKey() {
        return platformPubKey;
    }

    public void setPlatformPubKey(String platformPubKey) {
        this.platformPubKey = platformPubKey;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public String getOperateId() {
        return operateId;
    }

    public void setOperateId(String operateId) {
        this.operateId = operateId;
    }

    public String getPlatformSignature() {
        return platformSignature;
    }

    public void setPlatformSignature(String platformSignature) {
        this.platformSignature = platformSignature;
    }
}
