package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.dto.FeaturesDTO;
import cn.cslg.report.common.model.vo.PatentRightVo;
import cn.cslg.report.common.model.vo.PatentVO;

import cn.cslg.report.common.model.vo.SplitVO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.service.business.AssoTaskPatentSplitService;
import cn.cslg.report.service.business.FeatureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

@Tag(name = "特征管理")
@RestController
@RequestMapping(Constants.REPORT_API + "/feature")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class FeatureController {
    private final FeatureService featureService;
    private final AssoTaskPatentSplitService assoTaskPatentSplitService;

    @RequestMapping(value = "/splitPatentRight", method = RequestMethod.POST)
    @Operation(summary = "拆分权要")
    public String splitPatentRight(@RequestBody SplitVO splitVO) throws IOException {
        String res = featureService.splitPatentRight(splitVO);
        return res;
    }

    @RequestMapping(value = "/getFeatures", method = RequestMethod.GET)
    @Operation(summary = "获得报告创建人查询的特征")
    @Parameters(value = {
            @Parameter(name = "patentNo", description = "专利号", required = true),
            @Parameter(name = "ReportId", description = "报告Id"),
    })
    public String getFeatures(String patentNo, Integer reportId) throws IOException {
        String res = featureService.getFeatures(patentNo, reportId);
        return res;
    }

    @RequestMapping(value = "/addPatentRight", method = RequestMethod.POST)
    @Operation(summary = "保存权要")
    public String addPatentRight(@RequestBody List<PatentRightVo> patentRightVos) throws IOException {
        String res = featureService.addFeatures(patentRightVos);
        return res;
    }

    @RequestMapping(value = "/querySimFeaturePatent", method = RequestMethod.POST)
    @Operation(summary = "获得相似特征的专利号")
    public String querySimFeaturePatent(@RequestBody PatentVO patentVO) throws IOException {
        return Response.success(featureService.querySimFeaturePatent(patentVO));
    }

    @RequestMapping(value = "/getSplitMessage", method = RequestMethod.GET)
    @Operation(summary = "根据专利号和任务Id获得拆分信息")
    public String getSplitMessage(Integer taskId, String patentNo, Integer reportId) throws IOException {
        return Response.success(assoTaskPatentSplitService.getSplitMessage(taskId, patentNo, reportId));
    }

    @RequestMapping(value = "/getRights", method = RequestMethod.GET)
    @Operation(summary = "获得权要")
    public String getRights(String patentNo) throws IOException {
        return Response.success(featureService.getRightNames(patentNo));
    }


    @RequestMapping(value = "/addSingleFeature", method = RequestMethod.POST)
    @Operation(summary = "添加单个特征")
    public String addSingleFeature(@RequestBody FeaturesDTO featuresDTO) throws IOException {
        return featureService.addSingleFeature(featuresDTO);
    }

    @RequestMapping(value = "/deleteSingleFeature", method = RequestMethod.GET)
    @Operation(summary = "删除单个特征")
    public String deleteSingleFeature(Integer featureId) throws IOException {

        return featureService.deleteSingleFeature(featureId);
    }

    @RequestMapping(value = "/getFeatureList", method = RequestMethod.GET)
    @Operation(summary = "查询特征列表")
    public String getFeatureList(Integer reportId, Integer rightSort) throws IOException {

        return featureService.getFeatureList(reportId, rightSort);
    }

}