package com.cpop.oam.web;

import com.alibaba.fastjson.JSONObject;
import com.cpop.api.tencent.location.handler.TencentLocationHandler;
import com.cpop.api.tencent.wxWork.handler.WebHookSendHandler;
import com.cpop.core.annontation.StringArrayConvert;
import com.cpop.core.utils.CpopSignatureUtils;
import com.cpop.core.utils.RsaUtils;
import com.cpop.core.utils.SpringUtils;
import com.cpop.oam.business.bo.ApiTenantRequest;
import com.cpop.pay.framewok.handler.ecpp.EcppHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;
import okhttp3.Response;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author DB
 * @createTime 2023/09/15 17:44
 * @description
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CpopApiTests {

    @Autowired
    private WebHookSendHandler webHookSendHandler;

    /**
     * @descriptions 机器人发送测试
     * @author DB
     * @date 2023/10/12 15:19
     * @return: void
     */
    @Test
    public void webHookSendTest(){
        List<String> list = new ArrayList<>();
        list.add("17728500831");
        try {
            webHookSendHandler.webHookSendText("586442ba-6eeb-4a3c-937d-75faa4d9dbb9", list, "测试数据，不用管", false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void rsaDecrypt(){
        RsaUtils rsaUtils = SpringUtils.getBean(RsaUtils.class);
        String jambox0831 = rsaUtils.encrypt("jambox0831");
        String decrypt = rsaUtils.decrypt(jambox0831);
        System.out.println(decrypt);
    }

    @Test
    public void getSecurityKeyTest(){
        SpringUtils.getBean(EcppHandler.class).getSecurityKey();
    }

    @Test
    public void getTencentLocationApi() {
        JSONObject geocoder = SpringUtils.getBean(TencentLocationHandler.class).geocoder("114.4246835", "23.12707132", "UGLBZ-LBF3I-ETCGO-UUH5X-QDV45-3LFKA");
        System.out.println(geocoder);
    }

    /**
     * 新增租户
     * @author DB
     * @since 2024/2/28
     */
    @Test
    public void insertTenant() throws IOException, IllegalAccessException {
        com.alibaba.fastjson2.JSONObject jsonObject = SpringUtils.getBean(CpopSignatureUtils.class).sendSignaturePost("http://localhost:9440/Jambox-System/api/tenant/insertTenant",
                new ApiTenantRequest().setName("测试租户").setIsSuper(false), "100");
        System.out.println(jsonObject);
    }


}
