package com.ningdatech.pmapi.projectdeclared.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.projectdeclared.manage.DefaultDeclaredProjectManage;
import com.ningdatech.pmapi.projectdeclared.model.dto.DeclaredProjectListParamDTO;
import com.ningdatech.pmapi.projectdeclared.model.dto.DefaultDeclaredDTO;
import com.ningdatech.pmapi.projectdeclared.model.dto.ProjectDraftSaveDTO;
import com.ningdatech.pmapi.projectdeclared.model.vo.ProjectDraftVO;
import com.ningdatech.pmapi.projectdeclared.manage.DeclaredProjectManage;
import com.ningdatech.pmapi.projectlib.manage.ProjectLibManage;
import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq;
import com.ningdatech.pmapi.projectlib.model.vo.ProjectLibListItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Classname DeclaredProjectController
 * @Description 申报项目
 * @Date 2023/1/31 11:29
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/declared")
@Api(value = "DeclaredProject", tags = "申报管理-申报项目")
@RequiredArgsConstructor
public class DeclaredProjectController {
    private final DeclaredProjectManage declaredProjectManage;

    @ApiOperation(value = "申报项目已申报列表", notes = "申报项目已申报列表")
    @GetMapping("/list")
    public PageVo<ProjectLibListItemVO> list(@ModelAttribute ProjectListReq req) {
        return declaredProjectManage.projectLibList(req);
    }

    @ApiOperation(value = "申报项目草稿箱列表", notes = "申报项目草稿箱列表")
    @GetMapping("/draft")
    public PageVo<ProjectDraftVO> draft(@ModelAttribute DeclaredProjectListParamDTO params) {
        return declaredProjectManage.pageDraft(params);
    }

    @ApiOperation(value = "申报项目草稿箱详情", notes = "申报项目草稿箱详情")
    @GetMapping("/draft/{id}")
    public ProjectDraftVO draft(@PathVariable Long id) {
        return declaredProjectManage.draftDatail(id);
    }

    @ApiOperation(value = "申报项目保存至草稿箱", notes = "申报项目保存至草稿箱")
    @PostMapping("/save-to-draft")
    public Object saveToDraft(@Validated @RequestBody ProjectDraftSaveDTO dto) {
        return declaredProjectManage.saveToDraft(dto);
    }

    @ApiOperation(value = "申报项目", notes = "申报项目")
    @PostMapping("/start")
    public String startTheProcess(@Validated @RequestBody DefaultDeclaredDTO dto) {
        String instanceId = declaredProjectManage.startTheProcess(dto);
        return "启动流程实例 【" + instanceId + "】 成功";
    }
}
