package com.fkzy.warn.controller;

import com.fkzy.warn.common.constants.ResponseMsgConstants;
import com.fkzy.warn.common.response.ApiResponse;
import com.fkzy.warn.model.AImessage;
import com.fkzy.warn.model.params.AILawParams;
import com.fkzy.warn.model.params.LawGroupParam;
import com.fkzy.warn.service.FyApiService;
import com.fkzy.warn.service.LawCaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author zhangjing
 * @date 2024/05/21 11:22
 * @description
 */
@Api(tags = "数据相关")
@RestController
@RequestMapping("dataCenter/")
@Slf4j
public class DataCenterController {
    @Resource
    private LawCaseService lawCaseService;
    @Resource
    private FyApiService fyApiService;

    @RequestMapping(value = "judicialModelSave", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "司法模型")
    public ApiResponse judicialModelSave() {
        ApiResponse apiResponse = new ApiResponse();
        try {
            lawCaseService.judicialModelSave(null);
        } catch (Exception e) {
            log.error("查询错误,errMsg==={}", e.getMessage());
            e.printStackTrace();
            apiResponse.recordError(ResponseMsgConstants.OPERATE_FAIL);
        }
        return apiResponse;
    }

    @RequestMapping(value = "getLawGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "法律法规分组列表")
    public ApiResponse getLawGroup() {
        ApiResponse apiResponse = new ApiResponse();
        try {
            LawGroupParam lawGroupParam = new LawGroupParam();
            lawGroupParam.setOrgan("全国人民代表大会");
            lawGroupParam.setExprityDateList(Collections.singletonList("[全国人民代表大会]"));
            lawGroupParam.setSourceList(Collections.singletonList("[地方政府规章]"));
            lawGroupParam.setTimeliness("现行有效");
            lawGroupParam.setPageSize(20);
            lawGroupParam.setPubDate("2014");
            lawGroupParam.setPubDateList(Collections.singletonList("[地方政府规章]"));
            lawGroupParam.setTimelinessList(Collections.singletonList("[现行有效]"));
            lawGroupParam.setTitle("中国");
            lawGroupParam.setPageNum(1);

//            fyApiService.getLawGroup(lawGroupParam);
//            fyApiService.getLawGroupInfo("9f9d4094-d788-52f6-804d-0fc2a5dd462f");
            AILawParams aiLawParams = new AILawParams();
            aiLawParams.setStream(true);
            aiLawParams.setModel("中国法研LLM");
            AImessage aImessage = new AImessage();
            aImessage.setContent("借条和欠条的区别");
            aImessage.setRole("user");
            List<AImessage> aImessageList = new ArrayList<>();
            aImessageList.add(aImessage);
            aiLawParams.setMessages(aImessageList);
            fyApiService.sendAILaw(aiLawParams);
        } catch (Exception e) {
            log.error("查询错误,errMsg==={}", e.getMessage());
            e.printStackTrace();
            apiResponse.recordError(ResponseMsgConstants.OPERATE_FAIL);
        }
        return apiResponse;
    }

}
