package cn.cslg.report.controller.InvalidReReport;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.dto.ShareReportDTO;
import cn.cslg.report.common.model.dto.invalidReReport.ProofGroupDTO;
import cn.cslg.report.common.model.dto.invalidReReport.ProofGroupUpdateDTO;
import cn.cslg.report.common.model.vo.invalidReReport.ProofGroupVO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.exception.XiaoShiException;
import cn.cslg.report.service.business.InvalidReReport.ProofGroupService;
import cn.cslg.report.service.business.asso.AssoReportPersonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

/**
 * 报告分享管理的Controller层
 *
 * @Author lrj
 * @Data 2023/4/1
 */
@Tag(name = "证据组合管理")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(Constants.REPORT_API + "/proofGroup")
public class ProofGroupController {
    private final ProofGroupService proofGroupService;

    @Operation(summary = "添加证据组合")
    @PostMapping("/add")
    public String add(@RequestBody List<ProofGroupDTO> proofGroupDTOS) {
        if (proofGroupDTOS != null && proofGroupDTOS.size() != 0) {
            proofGroupService.addProofGroup(proofGroupDTOS);
            return Response.success("添加证据组合成功");
        } else {
            return Response.error("添加证据组合错误");
        }
    }

    @Operation(summary = "删除证据组合")
    @PostMapping("/delete")
    public String delete(@RequestBody List<Integer> ids) {
        if (ids != null && ids.size() != 0) {
            proofGroupService.deleteProofGroup(ids);
            return Response.success("删除成功");
        } else {
            return Response.error("删除失败");
        }
    }

    @Operation(summary = "修改证据组合")
    @PostMapping("/update")
    public String addPatentFile(@RequestBody ProofGroupUpdateDTO proofGroupUpdateDTO) throws IOException {
        if (proofGroupUpdateDTO != null) {
            proofGroupService.updateProofGroup(proofGroupUpdateDTO);
            return Response.success("更新成功");
        } else {
            return Response.error("更新失败");
        }
    }

    @Operation(summary = "查询证据组合")
    @PostMapping("/query")
    public String query(Integer id) throws IOException {
        if (id != null && id > 0) {
            try {
                ProofGroupVO proofGroupVO = proofGroupService.queryProofGroupDetail(id);
                return Response.success(proofGroupVO);
            } catch (XiaoShiException e) {
                return Response.error(e.getMessage());
            }
        } else {
            return Response.error("查询失败");
        }
    }

    @Operation(summary = "查询证据组合详情")
    @GetMapping("/queryDetailByInvalidId")
    public String queryDetailByInvalidId(Integer invalidReasonId) throws IOException {
        return Response.success( proofGroupService.queryDetailByInvalidId(invalidReasonId));

    }
}
