package cn.com.poc.softwareCopyRight;

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

import cn.com.gsst.dify_client.exception.DifyApiException;
import cn.com.poc.ai_software_copyright.agent.SoftwareCopyRightAgent;
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.JSONArray;
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;

    @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());
    }
}
