package nft.publish_nft;

import common.Constant;
import config.Config;
import util.Tools;
import util.ZxlSDKUtil;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) throws Exception {
        String url = "https://t12.baidu.com/it/u=2272949329,208470262&fm=30&app=106&f=JPEG?w=541&h=680&s=5CAB97554E237F1F509941790300D073";
        String operateId = UUID.randomUUID().toString();
        String seriesId = "zx5319ed299486075a64a93f628424004711325281_0b834869cc465224dcbc3ffd573dab1e9997335c5b15934198a8014de68956e9";
        NftPublish nftPublish = new NftPublish(Config.platformPubKey, "author", "name", url, url,
                Tools.getHash(url), "desc", "flag", 1, seriesId, 1, 1, 2000, operateId, "metaData", Constant.ZXL_CONSUME_TYPE_FIR);

        String taskId = nftPublish.publish(Config.platformPrivateKey);

        long startTime = System.currentTimeMillis();
        QueryPublishResult queryPublishResult = new QueryPublishResult(taskId);
        PublishResult publishResult = new PublishResult();
        while (Tools.checkTimeout(startTime, Constant.DEFAULT_TIMEOUT) && publishResult.getTaskStatus() < 7) {
            publishResult = queryPublishResult.queryPublishResult();
            TimeUnit.SECONDS.sleep(1);
        }

        if (publishResult.getTaskStatus() != 7) {
            System.out.println("publish nft failed: "+ publishResult.getTaskMsg());
        } else {
            System.out.println("publish nft success: " + publishResult.getNftIdBegin());
        }
    }
}
