package user.company;

import com.alibaba.fastjson.JSONObject;
import common.Resp;
import config.Config;
import util.HttpUtil;
import util.Tools;
import util.ZxlSDKUtil;

import java.io.File;

public class UploadLicense {
    File file;
    String platformIdentification;
    String platformPubKey;
    String platformSignData;

    public UploadLicense() {
    }

    public UploadLicense(File file) {
        this.file = file;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getPlatformIdentification() {
        return platformIdentification;
    }

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

    public String getPlatformPubKey() {
        return platformPubKey;
    }

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

    public String getPlatformSignData() {
        return platformSignData;
    }

    public void setPlatformSignData(String platformSignData) {
        this.platformSignData = platformSignData;
    }

    public int UploadLicense() throws Exception {
        if (this.file == null) {
            throw new IllegalArgumentException("file is null");
        }

        this.setPlatformIdentification(Config.platformIdentification);
        this.setPlatformPubKey(Config.platformPubKey);
        this.setPlatformSignData(ZxlSDKUtil.signByPriKey(Config.platformPrivateKey, this.platformIdentification));
        Resp resp = HttpUtil.formData("https://open.zxchain.qq.com/api/v1/user/business_license/upload_platform",
                ZxlSDKUtil.generateApiSign(), Tools.getJson(this), this.file);

        return (int) resp.getData().get("id");
    }
}
