package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.annotation.Permission;
import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.vo.PatentApplicantVO;
import cn.cslg.pas.common.model.vo.PatentInventorVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.domain.PatentApplicant;
import cn.cslg.pas.domain.PatentInventor;
import cn.cslg.pas.service.PatentApplicantService;
import cn.cslg.pas.service.PatentInventorService;
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 2021-12-24
 */
@Tag(name = "专利发明人")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/patent/inventor")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PatentInventorController {

    private final PatentInventorService patentInventorService;

    @GetMapping("list")
    @Operation(summary = "发明人列表")
    public String getList(PatentInventorVO params) {
        return Response.success(patentInventorService.getPageList(params));
    }

    @GetMapping("{id}")
    @Operation(summary = "根据ID获取发明人")
    public String getById(@PathVariable Integer id) {
        return Response.success(patentInventorService.getById(id));
    }

    @checkAuth(FunId = "/workspace/folder/merge/inventorMerge/add")
    @Permission(roles = {2})
    @PostMapping("add")
    @Operation(summary = "新增发明人")
    public String add(@RequestBody PatentInventor patentInventor) {
        return patentInventorService.add(patentInventor);
    }

    @checkAuth(FunId = "/workspace/folder/merge/inventorMerge/modify")
    @PostMapping("edit")
    @Operation(summary = "编辑发明人")
    public String edit(@RequestBody PatentInventor patentInventor) {
        return patentInventorService.edit(patentInventor);
    }

    @checkAuth(FunId = "/workspace/folder/merge/inventorMerge/delete")
    @PostMapping("delete")
    @Operation(summary = "删除发明人")
    public String delete(Integer id) {
        return patentInventorService.delete(id);
    }
}
