package nft.cos;

import common.Constant;
import common.Resp;
import config.Config;
import exception.ZXChainException;
import org.apache.commons.lang3.StringUtils;
import util.HttpUtil;
import util.Tools;
import util.ZxlSDKUtil;

public class QueryUrl {
    String seriesName;
    String platformIdentification;
    String userIdentification;

    public QueryUrl() {
    }

    public QueryUrl(String seriesName, String userIdentification) {
        this.seriesName = seriesName;
        this.userIdentification = userIdentification;
    }

    public String query() throws Exception {
        if (StringUtils.isEmpty(Config.platformIdentification)) {
            throw new IllegalArgumentException("平台唯一标识未配置");
        }

        if (StringUtils.isEmpty(this.userIdentification)) {
            throw new IllegalArgumentException("用户唯一标识不能为空");
        }

        if (StringUtils.isEmpty(this.seriesName)) {
            throw new IllegalArgumentException("seriesName不能为空");
        }

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

        return resp.getData().get("materialAddress").toString();
    }

    public String getSeriesName() {
        return seriesName;
    }

    public void setSeriesName(String seriesName) {
        this.seriesName = seriesName;
    }

    public String getPlatformIdentification() {
        return platformIdentification;
    }

    public void setPlatformIdentification(String platformIdentification) {
        this.platformIdentification = platformIdentification;
    }

    public String getUserIdentification() {
        return userIdentification;
    }

    public void setUserIdentification(String userIdentification) {
        this.userIdentification = userIdentification;
    }
}
