package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.vo.AddSyneryVo;
import cn.cslg.report.common.model.vo.CompareMessageVO;
import cn.cslg.report.common.model.vo.queryVo.QueryCMVO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.CompareMessage;
import cn.cslg.report.service.business.CompareMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Tag(name = "FTO对比记录")
@RestController
@RequestMapping(Constants.REPORT_API + "/compareMessage")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class CompareMessageController {
    private final CompareMessageService compareMessageService;
    @PostMapping("addCompareMessage")
    @Operation(summary = "添加FTO对比记录")
    public String addCompareMessage(@RequestBody List<CompareMessageVO> compareMessageVOS) throws IOException {
        if(compareMessageService.addCompareMessage(compareMessageVOS))
        {
            return Response.success("添加成功");
        }
      return Response.error("添加失败");
    }

    @PostMapping("updateCompareMessage")
    @Operation(summary = "更新FTO对比记录")
    public String updateCompareMessage(@RequestBody List<CompareMessage> compareMessages) throws IOException {
        if(compareMessageService.updateCompareMessage(compareMessages))
        {
            return Response.success("更新成功");
        }
        return Response.error("更新失败");
    }

    @PostMapping("removeCompareMessage")
    @Operation(summary = "删除FTO对比记录")
    public String removeCompareMessage(List<Integer> ids) throws IOException {
        if(compareMessageService.removeCompareMessage(ids))
        {
            return Response.success("删除成功");
        }
        return Response.error("删除失败");
    }

    @GetMapping("queryCompareMessage")
    @Operation(summary = "查找FTO对比记录")
    public String queryCompareMessage(Integer taskId,String patentNo,Integer reportId) throws IOException {
        return Response.success(compareMessageService.queryCompareMessage(taskId,patentNo,reportId));
    }

    @GetMapping("querySynery")
    @Operation(summary = "查找协同对比记录")
    public String querySynery(Integer taskId,String patentNo) throws IOException {
        return Response.success(compareMessageService.querySynery(taskId,patentNo));
    }

    @PostMapping("addSynery")
    @Operation(summary = "添加协同对比记录")
    public String addSynery(@RequestBody AddSyneryVo addSyneryVo) throws IOException {
        if(compareMessageService.addSynery(addSyneryVo)) {
            return Response.success();
        }
        return  Response.error();
    }
    @PostMapping("queryComparedMessage")
    @Operation(summary = "查找FTO已经对比的专利")
    public String queryComparedMessage(@RequestBody QueryCMVO queryCMVO) throws IOException {
        return Response.success(compareMessageService.queryComparedMessage(queryCMVO));
    }
    @GetMapping("queryAllCompareMessage")
    @Operation(summary = "查找对比结果（带协同结果）")
    public String queryAllCompareMessage(Integer reportId,String patentNo) throws IOException {
        return Response.success(compareMessageService.queryAllCompareMessage(patentNo,reportId));
    }
}
