package com.ningdatech.pmapi.projectlib.controller;

import com.alibaba.fastjson.JSONObject;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.common.helper.UserInfoHelper;
import com.ningdatech.pmapi.projectlib.manage.ProjectLibManage;
import com.ningdatech.pmapi.projectlib.model.req.ProjectApplicationListReq;
import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq;
import com.ningdatech.pmapi.projectlib.model.vo.ProjectApplicationVO;
import com.ningdatech.pmapi.projectlib.model.vo.ProjectDetailVO;
import com.ningdatech.pmapi.projectlib.model.vo.ProjectLibListItemVO;
import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO;
import com.ningdatech.pmapi.user.util.LoginUserUtil;
import com.wflow.workflow.bean.vo.ProcessDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * ProjectLibController
 * </p>
 *
 * @author WendyYang
 * @since 17:30 2023/2/1
 */
@RestController
@RequestMapping("/api/v1/project/lib")
@AllArgsConstructor
@Api(tags = "项目库")
public class ProjectLibController {

    private final ProjectLibManage projectLibManage;

    private final UserInfoHelper userInfoHelper;

    @GetMapping("/list")
    @ApiOperation("项目库列表")
    public PageVo<ProjectLibListItemVO> projectLibList(ProjectListReq req) {
        UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        return projectLibManage.projectLibListWithPermission(req,user);
    }

    @GetMapping("/history-list/{id}")
    @ApiOperation("项目历史版本列表")
    public JSONObject historyProjects(@PathVariable Long id) {
        return projectLibManage.historyProjects(id);
    }

    @GetMapping("/change-record/{id}")
    @ApiOperation("查看项目变更记录")
    public JSONObject changeRecord(@PathVariable Long id) {
        return projectLibManage.changeRecord(id);
    }

    @GetMapping("/application/list")
    @ApiOperation("应用列表")
    public PageVo<ProjectApplicationVO> applicationList(ProjectApplicationListReq req) {
        return projectLibManage.applicationList(req);
    }

    @GetMapping("/prePlan/{id}")
    @ApiOperation("获取项目初步方案详情")
    public ProjectDetailVO constructDetail (@PathVariable Long id){
        return projectLibManage.getPrePlanProjectDetail(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取项目详情")
    public ProjectDetailVO detail (@PathVariable Long id){
        return projectLibManage.getProjectDetail(id);
    }

    @GetMapping("/processSchedule/{projectId}")
    @ApiOperation("项目库申报项目当前进度详情")
    public List<ProcessDetailVO> processScheduleDetail(@PathVariable("projectId") Long projectId){
        return projectLibManage.processScheduleDetail(projectId);
    }

    @PostMapping("/exportList")
    @ApiOperation("项目库列表导出")
    @WebLog("项目库列表导出")
    public void exportList(@Valid @RequestBody ProjectListReq param, HttpServletResponse response){
        projectLibManage.exportList(param,response);
    }
}
