package com.hz.pm.api.projectlib.controller;

import com.alibaba.fastjson.JSONObject;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.gov.model.vo.GovBizProjectDetailVO;
import com.hz.pm.api.projectlib.manage.ProjectLibManage;
import com.hz.pm.api.projectlib.model.req.ProjectApplicationListReq;
import com.hz.pm.api.projectlib.model.req.ProjectListReq;
import com.hz.pm.api.projectlib.model.vo.ProjectApplicationVO;
import com.hz.pm.api.projectlib.model.vo.ProjectDetailVO;
import com.hz.pm.api.projectlib.model.vo.ProjectLibListItemVO;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.hz.pm.api.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("/all-list")
    @ApiOperation("包含申报项目列表和项目归集列表")
    public PageVo<ProjectLibListItemVO> projectAllList(ProjectListReq req) {
        UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        return projectLibManage.projectAllListWithPermission(req,user);
    }

    @GetMapping("/lib-list")
    @ApiOperation("包含申报项目列表和项目归集（运维项目）列表")
    public PageVo<ProjectLibListItemVO> libList(ProjectListReq req) {
        UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        return projectLibManage.libListWithPermission(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("/convert-to-collection/{projectCode}")
    @ApiOperation("申报项目转化为项目归集")
    public GovBizProjectDetailVO convertToCollection(@PathVariable String projectCode){
        return projectLibManage.convertToCollection(projectCode);
    }

    @GetMapping("/detail/{projectCode}")
    @ApiOperation("获取项目详情(编号)")
    public ProjectDetailVO detailProjectCode (@PathVariable String projectCode){
        return projectLibManage.detailProjectCode(projectCode);
    }

    @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);
    }
}
