package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.dto.AssoStructurePatentAddNewBatchDTO;
import cn.cslg.pas.common.model.dto.AssoStructurePatentQueryDTO;
import cn.cslg.pas.common.model.dto.AssoStructurePatentUpdateDTO;
import cn.cslg.pas.common.model.vo.AssoStructurePatentVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.exception.XiaoShiException;
import cn.cslg.pas.service.IStructurePatentService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 产品架构专利号标引的Controller层
 *
 * @Author chenyu
 * @Date 2023/3/15
 */
@Tag(name = "专题库标引管理模块")
@RequiredArgsConstructor
@Slf4j
@RequestMapping(Constants.API_VERSION_V2 + "/productStructurePatentIndex")
@RestController
public class ProductStructurePatentIndexController {
    private final IStructurePatentService structurePatentService;

    @Operation(summary = "更新标引")
    @PostMapping("/update")
    public String update(@RequestBody AssoStructurePatentUpdateDTO assoStructurePatentUpdateDTO) {
        log.info("开始处理【更新标引】的请求，请求参数为：{}", assoStructurePatentUpdateDTO);
        try {
            structurePatentService.update(assoStructurePatentUpdateDTO);
        } catch (XiaoShiException e) {
            return Response.error(e.getMessage());
        }
        return Response.success("更新标引完成");
    }

    @Operation(summary = "批量新增标引")
    @PostMapping("/addNewBatch")
    public String addNewBatch(@RequestBody AssoStructurePatentAddNewBatchDTO assoStructurePatentAddNewBatchDTO) {
        log.info("开始处理【批量新增标引】的请求，请求参数为：{}", assoStructurePatentAddNewBatchDTO);
        structurePatentService.addNewBatch(assoStructurePatentAddNewBatchDTO);
        return Response.success("批量新增标引完成");
    }

    @Operation(summary = "查询标引")
    @PostMapping("/query")
    public String query(@RequestBody AssoStructurePatentQueryDTO assoStructurePatentQueryDTO) {
        log.info("开始处理【查询标引】的业务，参数为：{}", assoStructurePatentQueryDTO);
        List<AssoStructurePatentVO> query = structurePatentService.query(assoStructurePatentQueryDTO);
        return Response.success(query);
    }

}
