package cn.com.poc.softwareCopyRight;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import cn.com.gsst.dify_client.exception.DifyApiException;
import cn.com.poc.ai_software_copyright.agent.SoftwareCopyRightAgent;
import cn.com.poc.ai_software_copyright.strategy.impl.InformationGenerationStrategy;
import cn.com.poc.common.config.DifyConfigProperties;
import cn.com.poc.ai_software_copyright.contant.AiSoftWareCopyRightRedisKey;
import cn.com.poc.ai_software_copyright.convert.BizSoftwareCopyrightConvert;
import cn.com.poc.ai_software_copyright.dto.SoftwareCopyRightDto;
import cn.com.poc.ai_software_copyright.entity.BizSoftwareCopyrightEntity;
import cn.com.poc.ai_software_copyright.service.BizSoftwareCopyrightService;
import cn.com.poc.common.service.RedisService;
import cn.com.yict.framemax.core.spring.SingleContextInitializer;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

/**
 * @author alex.yao
 * @date 2026/1/5
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = SingleContextInitializer.class)
@WebAppConfiguration
public class AgentTest {

    @Resource
    private RedisService redisService;

    @Resource
    private BizSoftwareCopyrightService bizSoftwareCopyrightService;

    @Resource
    private SoftwareCopyRightAgent softwareCopyRightAgent;

    @Resource
    private DifyConfigProperties difyConfigProperties;

    @Resource
    private InformationGenerationStrategy informationGenerationStrategy;

    @Test
    public void test_difyConfigProperties() {
        Map<String, String> apiKeys = difyConfigProperties.getApiKeys();
        System.out.println(apiKeys);

        System.out.println(apiKeys.get("technical-content"));

        System.out.println(informationGenerationStrategy.getCallbackURL());
    }


    @Test
    public void test_agent() throws DifyApiException, IOException, InterruptedException {
        BizSoftwareCopyrightEntity bizSoftwareCopyrightEntity = bizSoftwareCopyrightService.get(6L);
        SoftwareCopyRightDto softwareCopyRightDto = BizSoftwareCopyrightConvert.entityToDto(bizSoftwareCopyrightEntity);

        softwareCopyRightAgent.generatedBaseDoc("SOFT_WARE_COPY_RIGHT_CALL_BACK:6", Collections.emptyList(),
                softwareCopyRightDto.getBaseInfo(),
                softwareCopyRightDto.getTechnicalContent());
    }

    @Test
    public void test() {
        String string = redisService.get(AiSoftWareCopyRightRedisKey.CALL_BACK + "6:structure").toString();
        JSONObject jsonObject = JSONObject.parseObject(string);
        JSONObject result = jsonObject.getJSONObject("result");
        System.out.println(result.toJSONString());
    }
}
