package com.jeequan;

import com.alibaba.fastjson.JSON;
import com.jeequan.jeepay.converter.MchInfoConverter;
import com.jeequan.jeepay.core.entity.MchModifyApplyment;
import com.jeequan.jeepay.db.entity.MchApplyment;
import com.jeequan.jeepay.db.entity.MchModifyApplymentEntity;
import com.jeequan.jeepay.db.entity.MchVideoAuthEntity;
import com.jeequan.jeepay.mgr.bootstrap.JeepayMgrApplication;
import com.jeequan.jeepay.service.impl.MchApplymentService;
import com.jeequan.jeepay.service.impl.MchModifyApplymentService;
import com.jeequan.jeepay.service.impl.MchVideoAuthService;
import com.jeequan.jeepay.service.impl.RateConfigService;
import com.jeequan.jeepay.thirdparty.channel.yspay.YspayMchModifyApplymentService;
import com.jeequan.jeepay.thirdparty.channel.zftpay.ZftpayMchApplymentService;
import com.jeequan.jeepay.thirdparty.service.ConfigContextQueryService;
import com.jeequan.jeepay.thirdparty.service.SaasConfigService;
import com.jeequan.jeepay.thirdparty.service.wxchannel.WechatChannelService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.MutablePair;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@Slf4j
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = JeepayMgrApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ATest {

    @Autowired
    private MchApplymentService mchApplymentService;

    @Autowired
    private MchModifyApplymentService modifyApplymentService;

    @Autowired
    private RateConfigService rateConfigService;

    @Autowired
    private SaasConfigService saasConfigService;

    @Autowired
    private YspayMchModifyApplymentService yspayMchModifyApplymentService;

    @Autowired
    private ZftpayMchApplymentService applymentService;

    @Autowired
    private MchInfoConverter infoConverter;

    @Autowired
    private ConfigContextQueryService configContextQueryService;

    @Autowired
    private WechatChannelService wechatChannelService;

    @Autowired
    private MchVideoAuthService mchVideoAuthService;

    @Autowired
    private MchInfoConverter mchInfoConverter;

    @Test
    public void test2() {
        saasConfigService.siteConfig("Test20240322",
                "www.baidu.com", "cert/e6e974ed-2211-417f-9b86-5b83ce6b8811.pfx", "cert/e6e974ed-2211-417f-9b86-5b83ce6b8811.pfx",
                null, null, null);
    }

    @Test
    public void test23() {
        MchApplyment mchApplyment = mchApplymentService.getById("B240508314178");
        MchModifyApplymentEntity mchModifyApplyment = modifyApplymentService.getById("BG240513NL2VAUAZ");
//        MchModifyApplymentModel mchModifyData = JSON.parseObject(mchModifyApplyment.getApplyDetailInfo(), MchModifyApplymentModel.class);

//        YspayIsvParams isvParams = ((YspayIsvParams) configContextQueryService.queryIsvParams(mchInfoConverter.toModel(mchApplyment)));
//
//        YspayKit.uploadEditRequest("CHG202405130034448", isvParams, mchModifyData.getNonLegSettleAuthPic(), "B005");

        MutablePair<MchModifyApplyment, com.jeequan.jeepay.core.entity.MchApplyment> queryModifyResult = yspayMchModifyApplymentService.queryModifyResult(new MutablePair<>(infoConverter.toModel(mchModifyApplyment), infoConverter.toModel(mchApplyment)));
        log.info(JSON.toJSONString(queryModifyResult));


    }

    @Test
    public void test24() {
        MchVideoAuthEntity entity = mchVideoAuthService.getById(1774711199081197570L);
        wechatChannelService.videoDataColl(entity);
    }

//    @Test
//    public void testYsUpload() {
//        MchApplyment mchApplyment = mchApplymentService.getById("B240227861175");
//        YspayIsvParams isvParams = (YspayIsvParams) configContextQueryService.queryIsvParams(infoConverter.toModel(mchApplyment));
//        YspayKit.uploadEditRequest("CHG202403270017089", isvParams, "https://t7.baidu.com/it/u=810585695,3039658333&fm=193&f=GIF", "B008");
//    }


    @Test
    public void test() {
        MchApplyment mchApplyment = mchApplymentService.getById("B240430602427");

        rateConfigService.saveMchApplymentRate(mchApplyment);

        MchApplyment mchApplyment2 = mchApplymentService.getById("B240430023467");

        rateConfigService.saveMchApplymentRate(mchApplyment2);
    }

//    public static void main(String[] args) {
//        String passwordEncode = new BCryptPasswordEncoder().encode("HE3ShNfE");
//
//        System.out.println(passwordEncode);
//    }
}
