package nft.buy;

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

public class StatusUpdate {
    String platformPubKey;
    String operatorPubKey;
    String nftId;
    int transStatus;
    int transPrice;
    String operateId;
    String signature;
    String platformSignature;

    public StatusUpdate() {
    }

    public StatusUpdate(String operatorPubKey, String nftId, int transStatus, int transPrice, String operateId) {
        this.operatorPubKey = operatorPubKey;
        this.nftId = nftId;
        this.transStatus = transStatus;
        this.transPrice = transPrice;
        this.operateId = operateId;
    }

    public String updateStatus(String priKey) throws Exception {
        this.setPlatformPubKey(Config.platformPubKey);
        String signData = Tools.getSignData(
                this.platformPubKey,
                this.operatorPubKey,
                "nft_update_sell",
                this.nftId,
                this.transStatus,
                this.transPrice,
                this.operateId
        );
        this.setSignature(ZxlSDKUtil.signByPriKey(priKey, signData));
        this.setPlatformSignature(ZxlSDKUtil.signByPriKey(Config.platformPrivateKey, signData));

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

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

    public String getPlatformPubKey() {
        return platformPubKey;
    }

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

    public String getOperatorPubKey() {
        return operatorPubKey;
    }

    public void setOperatorPubKey(String operatorPubKey) {
        this.operatorPubKey = operatorPubKey;
    }

    public String getNftId() {
        return nftId;
    }

    public void setNftId(String nftId) {
        this.nftId = nftId;
    }

    public int getTransStatus() {
        return transStatus;
    }

    public void setTransStatus(int transStatus) {
        this.transStatus = transStatus;
    }

    public int getTransPrice() {
        return transPrice;
    }

    public void setTransPrice(int transPrice) {
        this.transPrice = transPrice;
    }

    public String getOperateId() {
        return operateId;
    }

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

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public String getPlatformSignature() {
        return platformSignature;
    }

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