package com.ningdatech.pmapi.performance.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.performance.manage.PerformanceAppraisalPlanManage;
import com.ningdatech.pmapi.performance.model.dto.AddAppraisalObjectDTO;
import com.ningdatech.pmapi.performance.model.dto.PerformanceAppraisalCreateDTO;
import com.ningdatech.pmapi.performance.model.dto.PerformanceAppraisalEditDTO;
import com.ningdatech.pmapi.performance.model.dto.PerformanceAppraisalProjectGroupSaveDTO;
import com.ningdatech.pmapi.performance.model.req.PerformanceAppraisalListReq;
import com.ningdatech.pmapi.performance.model.vo.PerformanceAppraisalApplicationVO;
import com.ningdatech.pmapi.performance.model.vo.PerformanceAppraisalProjectGroupVO;
import com.ningdatech.pmapi.performance.model.vo.PerformanceAppraisalProjectVO;
import com.ningdatech.pmapi.performance.model.vo.PerformanceAppraisalVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Classname PerformanceAppraisalController
 * @Description
 * @Date 2023/6/19 14:16
 * @Author PoffyZhang
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "绩效评价-评价计划")
@RequestMapping("/api/v1/performance-appraisal/plan")
public class PerformanceAppraisalPlanController {

    private final PerformanceAppraisalPlanManage performanceAppraisalPlanManage;

    @GetMapping("/list")
    @ApiOperation("评价计划列表")
    public PageVo<PerformanceAppraisalVO> list(PerformanceAppraisalListReq req) {
        return performanceAppraisalPlanManage.list(req);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("评价计划详情")
    public PerformanceAppraisalVO detail(@PathVariable Long id) {
        return performanceAppraisalPlanManage.detail(id);
    }

    @PostMapping("/create")
    @ApiOperation("绩效评价创建")
    @WebLog("绩效评价创建")
    public String create(@Valid @RequestBody PerformanceAppraisalCreateDTO createDTO) {
        return performanceAppraisalPlanManage.create(createDTO);
    }

    @PostMapping("/addProject")
    @ApiOperation("评价计划-添加待评价项目")
    @WebLog("评价计划-添加待评价项目")
    public String addProject(@Valid @RequestBody AddAppraisalObjectDTO addDTO) {
        return performanceAppraisalPlanManage.addProject(addDTO);
    }

    @PostMapping("/addApplication")
    @ApiOperation("评价计划-添加待评价应用")
    @WebLog("评价计划-添加待评价应用")
    public String addApplication(@Valid @RequestBody AddAppraisalObjectDTO addDTO) {
        return performanceAppraisalPlanManage.addApplication(addDTO);
    }

    @PostMapping("/edit")
    @ApiOperation("编辑绩效评价")
    @WebLog("编辑绩效评价")
    public String edit(@Valid @RequestBody PerformanceAppraisalEditDTO editDTO) {
        return performanceAppraisalPlanManage.edit(editDTO);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("绩效评价删除")
    @WebLog("绩效评价删除")
    public String delete(@PathVariable Long id) {
        return performanceAppraisalPlanManage.delete(id);
    }

    @GetMapping("/application-list")
    @ApiOperation("待添加应用列表")
    public PageVo<PerformanceAppraisalApplicationVO> applicationList(PerformanceAppraisalListReq req) {
        return performanceAppraisalPlanManage.applicationList(req);
    }

    @GetMapping("/project-list")
    @ApiOperation("项目分组-评价计划内待评价项目列表")
    public PageVo<PerformanceAppraisalProjectVO> projectList(PerformanceAppraisalListReq req) {
        return performanceAppraisalPlanManage.projectList(req);
    }

    @GetMapping("/group/list/{appraisalId}")
    @ApiOperation("绩效评价分组列表")
    public List<PerformanceAppraisalProjectGroupVO> groupList(@PathVariable Long appraisalId,
                                                              @RequestParam(required = false) String name) {
        return performanceAppraisalPlanManage.groupList(appraisalId,name);
    }

    @GetMapping("/group/detail/{id}")
    @ApiOperation("绩效评价分组详情")
    public PerformanceAppraisalProjectGroupVO groupDetail(@PathVariable Long id) {
        return performanceAppraisalPlanManage.groupDetail(id);
    }

    @PostMapping("/group/save")
    @ApiOperation("绩效评价分组保存")
    @WebLog("绩效评价分组保存")
    public String groupSave(@Valid @RequestBody PerformanceAppraisalProjectGroupSaveDTO dto) {
        return performanceAppraisalPlanManage.groupSave(dto);
    }

    @PostMapping("/group/delete/{id}")
    @ApiOperation("绩效评价分组删除")
    @WebLog("绩效评价分组删除")
    public String groupDelete(@PathVariable Long id) {
        return performanceAppraisalPlanManage.groupDelete(id);
    }
}
