package com.ningdatech.pmapi.projectdeclared.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.projectdeclared.manage.ConstructionManage;
import com.ningdatech.pmapi.projectdeclared.manage.ProjectAdjustmentManage;
import com.ningdatech.pmapi.projectdeclared.manage.PurchaseManage;
import com.ningdatech.pmapi.projectdeclared.model.dto.ContractSaveDTO;
import com.ningdatech.pmapi.projectdeclared.model.dto.PreInsSaveDTO;
import com.ningdatech.pmapi.projectdeclared.model.dto.PurchaseSaveDTO;
import com.ningdatech.pmapi.projectdeclared.model.vo.ContractVO;
import com.ningdatech.pmapi.projectdeclared.model.vo.PreInsVO;
import com.ningdatech.pmapi.projectdeclared.model.vo.PurchaseVO;
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.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Classname ConstructionController
 * @Description 申报项目-建设中
 * @Date 2023/5/29 09:29
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/declared/construction")
@Api(value = "ConstructionController", tags = "申报管理-建设中")
@RequiredArgsConstructor
public class ConstructionController {
    private final ConstructionManage constructionManage;

    @ApiOperation(value = "待合同备案的项目列表", notes = "合同备案的项目列表")
    @GetMapping("/contract/project-list")
    public PageVo<ProjectLibListItemVO> projectlist(@ModelAttribute ProjectListReq req) {
        return constructionManage.projectLibList(req);
    }

    @GetMapping("/contract/export")
    @ApiOperation("待合同备案的项目列表导出")
    @WebLog("待合同备案的项目列表导出")
    public void exportList(ProjectListReq req, HttpServletResponse response){
        ExcelDownUtil.downXls(response,req,constructionManage::exportList);
    }

    @ApiOperation(value = "合同备案的详情-通过项目ID", notes = "合同备案的详情-通过项目ID")
    @GetMapping("/contract/detail/{projectId}")
    public ContractVO detailContractByProjectId(@PathVariable Long projectId) {
        return constructionManage.detailContractByProjectId(projectId);
    }

    @ApiOperation(value = "填写合同信息", notes = "填写合同信息")
    @WebLog("填写合同信息")
    @PostMapping("/submit-contract")
    public String submitContract(@Validated @RequestBody ContractSaveDTO dto) {
        return constructionManage.submitContract(dto);
    }

    @ApiOperation(value = "待初验备案的项目列表", notes = "待初验备案的项目列表")
    @GetMapping("/pre-ins/project-list")
    public PageVo<ProjectLibListItemVO> preProjectList(@ModelAttribute ProjectListReq req) {
        return constructionManage.preProjectlist(req);
    }

    @GetMapping("/pre-ins/export")
    @ApiOperation("待初验备案的项目列表导出")
    @WebLog("待初验备案的项目列表导出")
    public void exportPreList(ProjectListReq req, HttpServletResponse response){
        ExcelDownUtil.downXls(response,req,constructionManage::exportPreList);
    }

    @ApiOperation(value = "初验备案的详情-通过项目ID", notes = "初验备案的详情-通过项目ID")
    @GetMapping("/pre-ins/detail/{projectId}")
    public PreInsVO detailPreInsByProjectId(@PathVariable Long projectId) {
        return constructionManage.detailPreInsByProjectId(projectId);
    }

    @ApiOperation(value = "填写初验信息", notes = "填写初验信息")
    @WebLog("填写初验信息")
    @PostMapping("/submit-pre-ins")
    public String submitPreIns(@Validated @RequestBody PreInsSaveDTO dto) {
        return constructionManage.submitPreIns(dto);
    }
}
