package com.liquidnet.service.zxlnft;

import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
import com.liquidnet.common.third.zxlnft.util.ZxlWalletSdkUtil;
import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.File;

/**
 * @author AnJiabin <anjiabin@zhengzai.tv>
 * @version V1.0
 * @Description: TODO
 * @class: TestZxlnftSdkUtil
 * @Package com.liquidnet.common.third.zxlnft.test
 * @Copyright: LightNet @ Copyright (c) 2021
 * @date 2022/2/18 13:49
 */
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class TestZxlnftSdkUtil {
    @Autowired
    private ZxlWalletSdkUtil zxlWalletSdkUtil;

    @Autowired
    private ZxlnftSdkUtil zxlnftSdkUtil;

    @Autowired
    private ZxlnftConfig zxlnftConfig;

    @Autowired
    private ZxlnftBiz zxlnftBiz;

    @Test
    public void nft001RegisterVerifyCode(){
        Nft001RegisterVerifyCodeReqDto reqDto = Nft001RegisterVerifyCodeReqDto.getNew();
        reqDto.setMobile("13811314082");
        ZxlnftResponseDto<Nft001RegisterVerifyCodeRespDto> resp = zxlnftSdkUtil.nft001RegisterVerifyCode(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft002RegisterPerson(){
        Nft002RegisterPersonReqDto reqDto = Nft002RegisterPersonReqDto.getNew();
        reqDto.setPersonName("安家宾");
//        reqDto.setEmail("");
        reqDto.setMobile("13811314082");
        reqDto.setVerifyCode("669340");
        reqDto.setIdCard("142323198302062216");
        reqDto.setCardType(Integer.valueOf(ZxlnftEnum.CardTypeEnum.ID_CARD.getCode()));
        ZxlnftResponseDto<Nft002RegisterPersonRespDto> resp = zxlnftSdkUtil.nft002RegisterPerson(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft003RegisterPersonPlatform(){
        Nft003RegisterPersonPlatformReqDto reqDto = Nft003RegisterPersonPlatformReqDto.getNew();
        reqDto.setPersonName("安家宾");
//        reqDto.setEmail("");
        reqDto.setMobile("13811314082");
        reqDto.setIdCard("142323198302062216");
        reqDto.setCardType(Integer.valueOf(ZxlnftEnum.CardTypeEnum.ID_CARD.getCode()));
        ZxlnftResponseDto<Nft003RegisterPersonPlatformRespDto> resp = zxlnftSdkUtil.nft003RegisterPersonPlatform(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft004BusinessLicenseUpload(){
        Nft004BusinessLicenseUploadReqDto reqDto = Nft004BusinessLicenseUploadReqDto.getNew();
        reqDto.setFile(new File("/Users/anjiabin/Downloads/zxl_image_test_001.jpg"));
        reqDto.setMobile("13811314082");
        reqDto.setVerifyCode("123456");
        ZxlnftResponseDto<Nft004BusinessLicenseUploadRespDto> resp = zxlnftSdkUtil.nft004BusinessLicenseUpload(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft005BusinessLicenseUploadPlatform(){
        Nft005BusinessLicenseUploadPlatformReqDto reqDto = Nft005BusinessLicenseUploadPlatformReqDto.getNew();
        reqDto.setFile(new File("/Users/anjiabin/Downloads/zxl_image_test_001.jpg"));
        ZxlnftResponseDto<Nft005BusinessLicenseUploadPlatformRespDto> resp = zxlnftSdkUtil.nft005BusinessLicenseUploadPlatform(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft006OfficialLetterUpload(){
        Nft006OfficialLetterUploadReqDto reqDto = Nft006OfficialLetterUploadReqDto.getNew();
        reqDto.setFile(new File("/Users/anjiabin/Downloads/zxl_image_test_001.jpg"));
        reqDto.setMobile("13811314082");
        reqDto.setVerifyCode("123456");
        ZxlnftResponseDto<Nft006OfficialLetterUploadRespDto> resp = zxlnftSdkUtil.nft006OfficialLetterUpload(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft007OfficialLetterUploadPlatform(){
        Nft007OfficialLetterUploadPlatformReqDto reqDto = Nft007OfficialLetterUploadPlatformReqDto.getNew();
        reqDto.setFile(new File("/Users/anjiabin/Downloads/zxl_image_test_001.jpg"));
        ZxlnftResponseDto<Nft007OfficialLetterUploadPlatformRespDto> resp = zxlnftSdkUtil.nft007OfficialLetterUploadPlatform(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft008QueryImageModeration(){
        Nft008QueryImageModerationReqDto reqDto = Nft008QueryImageModerationReqDto.getNew();
        reqDto.setImageUrl("https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg");
//        reqDto.setIntrval(0);
//        reqDto.setMaxFrames(1);
        ZxlnftResponseDto<Nft008QueryImageModerationRespDto> resp = zxlnftSdkUtil.nft008QueryImageModeration(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft009RegisterCompany(){
        Nft009RegisterCompanyReqDto reqDto = Nft009RegisterCompanyReqDto.getNew();
        reqDto.setEpName("企业名称");
//        reqDto.setEmail();
        reqDto.setVerifyCode("325588");
//        reqDto.setCreditCode("91110101330367841P");
        reqDto.setCreditCode("91110101330367841P");
        reqDto.setBusiLicenseId(12222);
//        reqDto.setOfficialLetterId();
        reqDto.setRepresentativeName("沈总");
        reqDto.setContact("安家宾");
        reqDto.setMobile("13811314082");
        reqDto.setIdcard("142323198302062216");
        reqDto.setCardType(Integer.parseInt(ZxlnftEnum.CardTypeEnum.ID_CARD.getCode()));
//        reqDto.setPlatformName();c
//        reqDto.setPlatformUrl();
//        reqDto.setBusinessType();

        ZxlnftResponseDto<Nft009RegisterCompanyRespDto> resp = zxlnftSdkUtil.nft009RegisterCompany(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft010RegisterCompanyPlatform(){
        Nft010RegisterCompanyPlatformReqDto reqDto = Nft010RegisterCompanyPlatformReqDto.getNew();
        reqDto.setEpName("北京正在映画互联网科技有限公司");
//        reqDto.setEmail();
        reqDto.setCreditCode("91110101330367841P");
        reqDto.setBusiLicenseId(12222);
//        reqDto.setOfficialLetterId();
        reqDto.setRepresentativeName("沈总");
        reqDto.setContact("安家宾");
        reqDto.setMobile("13811314082");
        reqDto.setIdcard("142323198302062216");
        reqDto.setCardType(Integer.parseInt(ZxlnftEnum.CardTypeEnum.ID_CARD.getCode()));
//        reqDto.setPlatformName();c
//        reqDto.setPlatformUrl();
//        reqDto.setBusinessType();

        ZxlnftResponseDto<Nft010RegisterCompanyPlatformRespDto> resp = zxlnftSdkUtil.nft010RegisterCompanyPlatform(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft011UserQueryVerifyCode(){
        Nft011UserQueryVerifyCodeReqDto reqDto = Nft011UserQueryVerifyCodeReqDto.getNew();
        //查询用户信息 发送手机验证码
//        reqDto.setType(1);
//        reqDto.setCardNo("142323198302062216");
//        reqDto.setScene(1);

        //nft平台绑定地址 发送邮箱验证码
        reqDto.setType(1);
        reqDto.setCardNo("142323198302062216");
        reqDto.setScene(2);
        ZxlnftResponseDto<Nft011UserQueryVerifyCodeRespDto> resp = zxlnftSdkUtil.nft011UserQueryVerifyCode(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft012UserQuery(){
        Nft012UserQueryReqDto reqDto = Nft012UserQueryReqDto.getNew();
        reqDto.setType(2);
        reqDto.setCardNo("142323198302062216");
        reqDto.setVerifyCode("676291");
        ZxlnftResponseDto<Nft012UserQueryRespDto> resp = zxlnftSdkUtil.nft012UserQuery(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft013IdentityBindSubmit(){
        Nft013IdentityBindSubmitReqDto reqDto = Nft013IdentityBindSubmitReqDto.getNew();
        reqDto.setPubKey(zxlnftConfig.getNftPlatformPubKey());
        reqDto.setUserIdentification("4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef");
        reqDto.setSignData(zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),reqDto.getUserIdentification()));
        reqDto.setFaceResultId("122");
        ZxlnftResponseDto<Nft013IdentityBindSubmitRespDto> resp = zxlnftSdkUtil.nft013IdentityBindSubmit(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft014IdentityBindSubmitByTrusted(){
        Nft014IdentityBindSubmitByTrustedReqDto reqDto = Nft014IdentityBindSubmitByTrustedReqDto.getNew();
        reqDto.setUserPubKey(zxlnftConfig.getNftPlatformPubKey());
        reqDto.setUserIdentification("4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef");
        String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),reqDto.getUserIdentification());
        reqDto.setUserSignData(signature);
        ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> resp = zxlnftSdkUtil.nft014IdentityBindSubmitByTrusted(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft015IdentityBindPlatformSelf(){
        Nft015IdentityBindPlatformSelfReqDto reqDto = Nft015IdentityBindPlatformSelfReqDto.getNew();
        reqDto.setPubKey(zxlnftConfig.getNftPlatformPubKey());
        reqDto.setUserIdentification("4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef");
        reqDto.setVerifyCode("061628");
        String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),reqDto.getUserIdentification());
        reqDto.setSignData(signature);
        ZxlnftResponseDto<Nft015IdentityBindPlatformSelfRespDto> resp = zxlnftSdkUtil.nft015IdentityBindPlatformSelf(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft016IdentityBindQuery(){
        Nft016IdentityBindQueryReqDto reqDto = Nft016IdentityBindQueryReqDto.getNew();
        reqDto.setAddressList("ZXa66c8a684727d0f9aaa434044362aa8a18b61bb4");
        ZxlnftResponseDto<Nft016IdentityBindQueryRespDto> resp = zxlnftSdkUtil.nft016IdentityBindQuery(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft017IdentityVerifyIdentity(){
        Nft017IdentityVerifyIdentityReqDto reqDto = Nft017IdentityVerifyIdentityReqDto.getNew();
        reqDto.setAddress("ZXa66c8a684727d0f9aaa434044362aa8a18b61bb4");
        reqDto.setFaceResultId("111");
        ZxlnftResponseDto<Nft017IdentityVerifyIdentityRespDto> resp = zxlnftSdkUtil.nft017IdentityVerifyIdentity(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft021UploadUrl(){
        Nft021UploadUrlReqDto reqDto = Nft021UploadUrlReqDto.getNew();
//        reqDto.setSeriesName("");
        reqDto.setPlatformIdentification(zxlnftConfig.getPlatformIdentification());
//        reqDto.setUserIdentification(zxlnftConfig.getPlatformIdentification());
        ZxlnftResponseDto<Nft021UploadUrlRespDto> resp = zxlnftSdkUtil.nft021UploadUrl(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft022UploadSecret(){
        Nft022UploadSecretReqDto req = Nft022UploadSecretReqDto.getNew();
//        req.setSeriesName("");
        req.setTimestamp(DateUtil.getNowSeconds().toString());
        req.setPubKey(zxlnftConfig.getNftPlatformPubKey());
        req.setUserPubKey(zxlnftConfig.getNftPlatformPubKey());

        //系列为空
        String pubData = req.getTimestamp() + "_" + req.getUserPubKey();
        String userData = req.getTimestamp();
        //系列不为空
//        String pubData = req.getTimestamp() + "_" + req.getSeriesName() + "_" + req.getUserPubKey();
//        String userData = req.getTimestamp() + "_" + req.getSeriesName();

        req.setPubSignedData(zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),pubData));
        req.setUserSignedData(zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),userData));

        ZxlnftResponseDto<Nft022UploadSecretRespDto> resp = zxlnftSdkUtil.nft022UploadSecret(req);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft023PointApply(){
        Nft023PointApplyReqDto reqDto = Nft023PointApplyReqDto.getNew();
        reqDto.setApplyerAddr("ZXa66c8a684727d0f9aaa434044362aa8a18b61bb4");
        reqDto.setCount(200l);
        reqDto.setOperateId(IDGenerator.get32UUID());
        ZxlnftResponseDto<Nft023PointApplyRespDto> resp = zxlnftSdkUtil.nft023PointApply(reqDto);
        System.out.println(resp.toJson());
    }

    /**
     * 查询失败
     */
    @Test
    public void nft024PointApplyResult(){
        Nft024PointApplyResultReqDto reqDto = Nft024PointApplyResultReqDto.getNew();
        reqDto.setTaskId("337fe5cc-d509-418f-867f-378ca351e4ba_apply-point_1");
        ZxlnftResponseDto<Nft024PointApplyResultRespDto> resp = zxlnftSdkUtil.nft024PointApplyResult(reqDto);
        System.out.println(resp.toJson());
    }

//25	平台积分转移	api/v1/nft/point/transfer
//26	平台积分转移状态查询	api/v1/nft/point/transfer/result
//27	积分销毁	api/v1/nft/point/destroy
//28	查询积分销毁结果	api/v1/nft/point/destory/resul

    @Test
    public void nft029PointQuery(){
        Nft029PointQueryReqDto reqDto = Nft029PointQueryReqDto.getNew();
        reqDto.setAddr("ZXa66c8a684727d0f9aaa434044362aa8a18b61bb4");
        ZxlnftResponseDto<Nft029PointQueryRespDto> resp = zxlnftSdkUtil.nft029PointQuery(reqDto);
        System.out.println(resp.toJson());
    }
//30	NFT 系列声明	api/v1/nft/series/claim
//31	查询NFT系列声明结果	api/v1/nft/series/claim/result
//32	查询系列信息	api/v1/nft/series
//33	查询该账户资产归属的系列列表	api/v1/nft/series/list
    @Test
    public void nft034Publish(){
        Nft034PublishReqDto reqDto = Nft034PublishReqDto.getNew();
        reqDto.setAuthor("正在现场作者");
        reqDto.setName("正在现场NFT001");
        reqDto.setUrl("https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg");
        reqDto.setDisplayUrl("https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg");
        reqDto.setDesc("NFT描述信息");
        reqDto.setFlag("文创");
        reqDto.setPublishCount(10l);
//      reqDto.setSeriesId("");
        reqDto.setSeriesBeginIndex(1);
        reqDto.setSellStatus(Integer.parseInt(ZxlnftEnum.SellStatusEnum.CAN_SELL.getCode()));
        reqDto.setSellCount(1000l);
        reqDto.setOperateId(IDGenerator.get32UUID());
        reqDto.setMetaData("");

        ZxlnftResponseDto<Nft034PublishRespDto> resp = zxlnftSdkUtil.nft034Publish(reqDto);
        System.out.println(resp.toJson());
    }

    @Test
    public void nft035PublishResult(){
        Nft035PublishResultReqDto reqDto = Nft035PublishResultReqDto.getNew();
        reqDto.setTaskId("5d23ed47-dcb2-4672-99eb-060c04727a20_nft-publish_3");
        ZxlnftResponseDto<Nft035PublishResultRespDto> resp = zxlnftSdkUtil.nft035PublishResult(reqDto);
        System.out.println(resp.toJson());
    }
}
