package cn.cslg.pas.controller;


import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.vo.PatentKeywordsHighlightVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.domain.PatentKeywordsHighlight;
import cn.cslg.pas.service.PatentKeywordsHighlightService;
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.*;

/**
 * <p>
 * 专利关键词高亮 前端控制器
 * </p>
 *
 * @author 王岩
 * @since 2022-03-18
 */
@Tag(name = "专利关键词高亮模板")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/patent/keywords/highlight")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PatentKeywordsHighlightController {
    private final LoginUtils loginUtils;
    private final PatentKeywordsHighlightService patentKeywordsHighlightService;

    @GetMapping("list")
    @Operation(summary = "模板列表")
    public String getList(PatentKeywordsHighlightVO params) {
        return Response.success(patentKeywordsHighlightService.getPatentKeywordsHighlight(params));
    }

    @PostMapping("update")
    @Operation(summary = "更新模板")
    public String update(@RequestBody PatentKeywordsHighlight patentKeywordsHighlight) {
        patentKeywordsHighlightService.updatePatentKeywordsHighlight(patentKeywordsHighlight);
        return Response.success(true);
    }

    @PostMapping("default")
    @Operation(summary = "创建默认模板")
    public String getDefault(Integer projectId) {
        PatentKeywordsHighlight patentKeywordsHighlight = patentKeywordsHighlightService.initPatentKeywordsHighlight(projectId, loginUtils.getId(), false, "新模板");
        patentKeywordsHighlight.setConfig(null);
        return Response.success(patentKeywordsHighlight);
    }


    @PostMapping("delete")
    @Operation(summary = "删除模板")
    public String delete(Integer id) {
        patentKeywordsHighlightService.deletePatentKeywordsHighById(id);
        return Response.success(true);
    }
}

