package com.ningdatech.pmapi.performance.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.performance.manage.IndicatorConfigManage;
import com.ningdatech.pmapi.performance.model.dto.PerformanceIndicatorAppIndexSaveDTO;
import com.ningdatech.pmapi.performance.model.dto.PerformanceIndicatorProjectIndexSaveDTO;
import com.ningdatech.pmapi.performance.model.dto.PerformanceIndicatorProjectTemplateSaveDTO;
import com.ningdatech.pmapi.performance.model.req.PerformanceAppraisalListReq;
import com.ningdatech.pmapi.performance.model.vo.AppIndexVO;
import com.ningdatech.pmapi.performance.model.vo.ProjectIndexTemplateVO;
import com.ningdatech.pmapi.performance.model.vo.ProjectIndexVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 绩效评价-指标配置
 * @return
 * @author CMM
 * @since 2023/07/26 16:29
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "绩效评价-指标配置")
@RequestMapping("/api/v1/indicator-config")
public class IndicatorConfigController {

    private final IndicatorConfigManage indicatorConfigManage;

    @GetMapping("/project/index/template/list")
    @ApiOperation("项目指标模板列表")
    public PageVo<ProjectIndexTemplateVO> projectIndexTemplateList(PerformanceAppraisalListReq req) {
        return indicatorConfigManage.projectIndexTemplateList(req);
    }

    @GetMapping("/project/index/template/detail/{id}")
    @ApiOperation("项目指标配置模板详情")
    public ProjectIndexTemplateVO projectDetail(@PathVariable Long id) {
        return indicatorConfigManage.projectDetail(id);
    }

    @ApiOperation(value = "项目指标模版启用(禁用)", notes = "项目指标模版启用(禁用)")
    @PutMapping("/project/index/{templateId}/active/{state}")
    public String enOrDisProjectIndexTemplate(@PathVariable Long templateId,
                               @PathVariable Boolean state) {
        Boolean result = indicatorConfigManage.enOrDisProjectIndexTemplate(templateId, state);
        return Boolean.TRUE.equals(result)  ? "操作成功":"操作失败";
    }

    @PostMapping("/project/index/template/save")
    @ApiOperation("项目指标配置模板保存")
    @WebLog("项目指标配置模板保存")
    public String projectTemplateSave(@Valid @RequestBody PerformanceIndicatorProjectTemplateSaveDTO dto) {
        return indicatorConfigManage.projectTemplateSave(dto);
    }

    @PostMapping("/project/index/template/copy/{id}")
    @ApiOperation("项目指标配置模板复制")
    @WebLog("项目指标配置模板复制")
    public String projectTemplateCopy(@PathVariable Long id) {
        return indicatorConfigManage.projectTemplateCopy(id);
    }

    @PostMapping("/project/index/template/delete/{id}")
    @ApiOperation("项目指标配置模板删除")
    @WebLog("项目指标配置模板删除")
    public String projectTemplateDelete(@PathVariable Long id) {
        return indicatorConfigManage.projectTemplateDelete(id);
    }

    @GetMapping("/project/index/list")
    @ApiOperation("项目指标库列表")
    public PageVo<ProjectIndexVO> projectIndexList(PerformanceAppraisalListReq req) {
        return indicatorConfigManage.projectIndexList(req);
    }

    @PostMapping("/project/index/save")
    @ApiOperation("项目指标库新增指标保存")
    @WebLog("项目指标库新增指标保存")
    public String projectIndexSave(@Valid @RequestBody PerformanceIndicatorProjectIndexSaveDTO dto) {
        return indicatorConfigManage.projectIndexSave(dto);
    }

    @PostMapping("/project/index/delete/{id}")
    @ApiOperation("项目指标库指标删除")
    @WebLog("项目指标库指标删除")
    public String projectIndexDelete(@PathVariable Long id) {
        return indicatorConfigManage.projectIndexDelete(id);
    }

    @PostMapping("/project/index/detail/{id}")
    @ApiOperation("项目指标库项目指标详情")
    public ProjectIndexVO projectIndexDetail(@PathVariable Long id) {
        return indicatorConfigManage.projectIndexDetail(id);
    }

    @GetMapping("/app/index/list")
    @ApiOperation("应用指标库列表")
    public PageVo<AppIndexVO> appIndexList(PerformanceAppraisalListReq req) {
        return indicatorConfigManage.appIndexList(req);
    }

    @PostMapping("/app/index/save")
    @ApiOperation("应用指标库新增指标保存")
    @WebLog("应用指标库新增指标保存")
    public String appIndexSave(@Valid @RequestBody PerformanceIndicatorAppIndexSaveDTO dto) {
        return indicatorConfigManage.appIndexSave(dto);
    }

    @PostMapping("/app/index/delete/{id}")
    @ApiOperation("应用指标库指标删除")
    @WebLog("应用指标库指标删除")
    public String appIndexDelete(@PathVariable Long id) {
        return indicatorConfigManage.appIndexDelete(id);
    }

    @PostMapping("/app/index/detail/{id}")
    @ApiOperation("应用指标库应用指标详情")
    public AppIndexVO appIndexDetail(@PathVariable Long id) {
        return indicatorConfigManage.appIndexDetail(id);
    }

    @ApiOperation(value = "应用指标启用(禁用)", notes = "应用指标启用(禁用)")
    @PutMapping("/app/index/{appId}/active/{state}")
    public String enOrDisAppIndex(@PathVariable Long appId,
                                              @PathVariable Boolean state) {
        Boolean result = indicatorConfigManage.enOrDisAppIndex(appId, state);
        return Boolean.TRUE.equals(result) ? "操作成功":"操作失败";
    }
}
