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.utils.auth.checkAuth;
import cn.cslg.pas.domain.PatentApplicant;
import cn.cslg.pas.service.PatentApplicantService;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.model.vo.PatentApplicantVO;
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/applicant")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PatentApplicantController {

    private final PatentApplicantService patentApplicantService;

    @GetMapping("list")
    @Operation(summary = "申请人列表")
    public String getList(PatentApplicantVO params) {
        return Response.success(patentApplicantService.getPageList(params));
    }

    @GetMapping("/merge/list")
    @Operation(summary = "合并申请人列表")
    public String getMergeList(PatentApplicantVO params) {
        return Response.success(patentApplicantService.getMergeList(params));
    }

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

    @checkAuth(FunId = "/workspace/folder/merge/applicationMerge/add")
    @Permission(roles = {2})
    @PostMapping("add")
    @Operation(summary = "选择申请人")
    public String add(@RequestBody PatentApplicant patentApplicant) {
        return patentApplicantService.add(patentApplicant);
    }

    @checkAuth(FunId = "/workspace/folder/merge/applicationMerge/modify")
    @PostMapping("edit")
    @Operation(summary = "编辑申请人")
    public String edit(@RequestBody PatentApplicant patentApplicant) {
        return patentApplicantService.edit(patentApplicant);
    }

    @checkAuth(FunId = "/workspace/folder/merge/applicationMerge/delete")
    @PostMapping("delete")
    @Operation(summary = "删除申请人")
    public String delete(Integer id) {
        return patentApplicantService.delete(id);
    }

    @checkAuth(FunId = "/workspace/folder/merge/applicationMerge/merged/remove")
    @PostMapping("/merge/delete")
    @Operation(summary = "删除申请人（合并）")
    public String deleteMerge(Integer id, Integer mergeId) {
        return patentApplicantService.deleteMerge(id, mergeId);
    }
}
