package com.jwipc.tender.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.tender.constant.ModuleConst;
import com.jwipc.tender.dto.TenderCostContractDTO;
import com.jwipc.tender.dto.TenderSaveDTO;
import com.jwipc.tender.dto.UpdateTimeDTO;
import com.jwipc.tender.logic.TenderLogic;
import com.jwipc.tender.model.query.TenderQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p> 招标管理相关接口</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping(ModuleConst.MODULE_ROOT + "/rest")
public class TenderRestController {
    private final TenderLogic tenderLogic;

    /**
     * 招标管理 列表
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping(value = "list")
    public PageView list(TenderQuery query) {
        return tenderLogic.getList(query);
    }

    /**
     * 招标单 新增，修改，发布
     *
     * @param saveDTO
     * @return
     */
    @PostMapping("saveOrUpdate")
    public ResponseEntity saveOrUpdate(@RequestBody TenderSaveDTO saveDTO) {
        tenderLogic.saveOrUpdate(saveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 招标单 审批
     *
     * @param id     主键
     * @param remark 备注
     * @param status 状态 1:通过;0:驳回
     * @return
     */
    @PostMapping("approval")
    public ResponseEntity approval(Long id, String remark, Integer status) {
        tenderLogic.approval(id, remark, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 招标单 新增，修改，发布
     *
     * @param id 招标单主键
     * @return
     */
    @GetMapping("getDetail")
    public ResponseEntity getDetail(Long id) {
        final TenderSaveDTO detail = tenderLogic.getDetail(id);
        return ResponseEntity.ok(detail);
    }

    /**
     * 招标单 删除
     *
     * @param id 主键
     * @return
     */
    @PostMapping("remove")
    public ResponseEntity remove(Long id) {
        tenderLogic.remove(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 招标单 作废
     *
     * @param id 主键
     * @return
     */
    @PostMapping("toVoid")
    public ResponseEntity toVoid(Long id) {
        tenderLogic.toVoid(id);
        return ResponseEntity.ok().build();
    }


    /**
     * 修改招标单时间
     *
     * @return
     */
    @PostMapping("updateTime")
    public ResponseEntity updateTime(@RequestBody UpdateTimeDTO updateTimeDTO) {
        tenderLogic.updateTime(updateTimeDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 手动截标
     *
     * @param id 招标单id
     * @return
     */
    @PostMapping("stop")
    public ResponseEntity stop(Long id) {
        tenderLogic.stop(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商投标和报价情况
     *
     * @param id   招标单id
     * @param type 是否是投标情况1:是;0:否
     * @return
     */
    @GetMapping("supplierProcess")
    public PageView supplierProcess(Long id, Integer type) {
        return tenderLogic.supplierProcess(id, type);
    }

    @GetMapping("bargainingStatus")
    public PageView bargainingStatus(Long id){
        return tenderLogic.bargainingStatus(id);
    }


    @PostMapping("/zblist")
    public ResponseEntity zblistFindByList(Long zbId) {
        return ResponseEntity.ok(tenderLogic.zblistFindByList(zbId));
    }

    /**
     * 获取招标单的生成费用合同列表
     * @param tenderId 招标单id
     * @return 生成费用合同列表
     */
    @PostMapping("/getTenderCostContractList")
    public ResponseEntity<List<TenderCostContractDTO>> getTenderCostContractList(Long tenderId) {
        return ResponseEntity.ok(tenderLogic.getTenderCostContractList(tenderId));
    }

}
