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

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.hz.pm.api.filemanage.manage.ProjectFileManage;
import com.hz.pm.api.filemanage.model.param.ProjectFileListParam;
import com.hz.pm.api.filemanage.model.vo.ProjectApplyBorrowVO;
import com.hz.pm.api.filemanage.model.vo.ProjectFileListVO;
import com.hz.pm.api.filemanage.model.vo.ProjectFileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Classname ProjectFileController
 * @Description
 * @Date 2023/6/6 15:48
 * @Author PoffyZhang
 */
@RestController
@AllArgsConstructor
@Api(tags = "档案管理-项目档案")
@RequestMapping("/api/v1/file-manage/project-file")
@Validated
public class ProjectFileController {

    private final ProjectFileManage projectFileManage;

    @GetMapping("/list")
    @ApiOperation(value = "档案列表", notes = "档案列表")
    public PageVo<ProjectFileListVO> list(@ModelAttribute ProjectFileListParam param){
        return projectFileManage.list(param);
    }

    @GetMapping("/{projectId}")
    @ApiOperation(value = "档案详情", notes = "档案详情")
    public ProjectFileVO file(@PathVariable Long projectId){
        return projectFileManage.file(projectId);
    }

    @PostMapping("/want-read/{projectId}")
    @ApiOperation(value = "申请借阅", notes = "申请借阅")
    @WebLog("档案管理-项目档案-申请借阅")
    public String wantRead(@PathVariable Long projectId){
        String instanceId = projectFileManage.startApplyBorrowProcess(projectId);
        return "启动申请借阅流程实例 【" + instanceId + "】 成功";
    }

    @GetMapping("/wantRead-detail/{instanceId}")
    @ApiOperation(value = "借阅详情", notes = "借阅详情")
    public ProjectApplyBorrowVO wantReadDetail(@PathVariable String instanceId){
        return projectFileManage.wantReadDetail(instanceId);
    }

    @PostMapping("/download/{projectId}")
    @ApiOperation(value = "档案下载",notes = "档案下载")
    public void downloadFile(@PathVariable Long projectId,HttpServletResponse response){
        projectFileManage.downloadFile(projectId, response);
    }
}
