package com.jwipc.supplier.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.supplier.dto.SupplierQualificationApplySaveDTO;
import com.jwipc.supplier.dto.SupplierQualificationBaseDTO;
import com.jwipc.supplier.dto.SupplierQualificationChangeSaveDTO;
import com.jwipc.supplier.logic.SupplierQualificationLogic;
import com.jwipc.supplier.model.query.SupplierQualificationChangeQuery;
import com.jwipc.supplier.model.query.SupplierQualificationQuery;
import com.jwipc.supplier.model.query.SupplierQualificationSupplemntQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.jwipc.supplier.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> 供应商资质相关接口</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/supplierQualification/rest")
@RequiredArgsConstructor
@Slf4j
public class SupplierQualificationRestController {
    private final SupplierQualificationLogic supplierQualificationLogic;

    /**
     * 供应商资质变更申请分页列表
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("applyList")
    public PageView applyList(SupplierQualificationSupplemntQuery query) {
        return supplierQualificationLogic.getApplyList(query);
    }

    /**
     * 供应商资质变更申请中的供应商列表
     *
     * @param applyId 资质申请主键
     * @return
     */
    @GetMapping("applySupplierList")
    public ResponseEntity applySupplierList(Long applyId) {
        return ResponseEntity.ok(supplierQualificationLogic.getApplySupplierList(applyId));
    }

    /**
     * 供应商资质变更申请中的供应商列表
     *
     * @param applyId 资质申请主键
     * @return
     */
    @GetMapping("applyQualificationList")
    public ResponseEntity applyQualificationList(Long applyId) {
        return ResponseEntity.ok(supplierQualificationLogic.getApplyQualificationList(applyId));
    }

    /**
     * 供应商资质变更申请新增和修改保存
     *
     * @param applySaveDTO 保存对象
     * @return
     */
    @PostMapping("apply/saveOrUpdate")
    public ResponseEntity applySaveOrUpdate(@RequestBody SupplierQualificationApplySaveDTO applySaveDTO) {
        supplierQualificationLogic.applySaveOrUpdate(applySaveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质变更申请 提交
     *
     * @param id 资质变更申请主键
     * @return
     */
    @PostMapping("apply/submit")
    public ResponseEntity applySubmit(Long id) {
        supplierQualificationLogic.applySubmit(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 废弃
     */

    @PostMapping("apply/updateRemoveStatus")
    public ResponseEntity updateRemoveStatus(Long id) {
        supplierQualificationLogic.updateRemoveStatus(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质变更 分页列表
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("changeList")
    public PageView changeList(SupplierQualificationChangeQuery query) {
        return supplierQualificationLogic.getChangeList(query);
    }

    /**
     * 供应商资质变更详情中当前变更单的资质列表
     *
     * @param changeId 查询参数
     * @return
     */
    @GetMapping("changeItemList")
    public ResponseEntity changeList(Long changeId) {
        return ResponseEntity.ok(supplierQualificationLogic.getChangeItemList(changeId));
    }

    /**
     * 供应商资质列表接口
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("list")
    public PageView list(SupplierQualificationQuery query) {
        return supplierQualificationLogic.getList(query);
    }

    /**
     * 供应商资质变更 保存和修改接口
     *
     * @param supplierQualificationChangeSaveDTO 查询参数
     * @return
     */
    @PostMapping("changeSaveOrUpdate")
    public ResponseEntity changeSaveOrUpdate(
            @RequestBody SupplierQualificationChangeSaveDTO supplierQualificationChangeSaveDTO)
    {
        supplierQualificationLogic.changeSaveOrUpdate(supplierQualificationChangeSaveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质变更 商务审批驳回
     *
     * @param id     资质变更主键
     * @param remark 审批意见
     * @return
     */
    @PostMapping("changeBusinessReject")
    public ResponseEntity changeBusinessReject(
            Long id, String remark)
    {
        supplierQualificationLogic.changeBusinessReject(id, remark);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质变更 商务审批通过
     *
     * @param id     资质变更主键
     * @param remark 审批意见
     * @return
     */
    @PostMapping("changeBusinessPass")
    public ResponseEntity changeBusinessPass(
            Long id, String remark, String rows)
    {
        supplierQualificationLogic.changeBusinessPass(id, remark, rows);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质变更 商务审批驳回
     *
     * @param id     资质变更主键
     * @param remark 审批意见
     * @return
     */
    @PostMapping("changeSqeReject")
    public ResponseEntity changeSqeReject(
            Long id, String remark)
    {
        supplierQualificationLogic.changeSqeReject(id, remark);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质变更 商务审批通过
     *
     * @param id     资质变更主键
     * @param remark 审批意见
     * @return
     */
    @PostMapping("changeSqePass")
    public ResponseEntity changeSqePass(
            Long id, String remark)
    {
        supplierQualificationLogic.changeSqePass(id, remark);
        return ResponseEntity.ok().build();
    }


    /**
     * 供应商资质变更申请分页列表
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("warn/page")
    public PageView warnPage(SupplierQualificationQuery query) {
        return supplierQualificationLogic.warnPage(query);
    }


    /**
     * 供应商认证报告列表
     *
     * @param id                   供应商id
     * @param purchaseCategoryCode 采购品类编号
     * @return
     */
    @GetMapping("reportList")
    public PageView reportList(Long id, String purchaseCategoryCode) {
        return supplierQualificationLogic.getReportList(id, purchaseCategoryCode);
    }

    /**
     * 供应商认证保存
     *
     * @param supplierQualificationBaseDTOS 数据
     * @return
     */
    @PostMapping("reportSave")
    public ResponseEntity reportSave(@RequestBody List<SupplierQualificationBaseDTO> supplierQualificationBaseDTOS) {
        supplierQualificationLogic.reportSave(supplierQualificationBaseDTOS);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商资质更新
     *
     * @param supplierQualificationBaseDTOS 数据
     * @return
     */
    @PostMapping("update")
    public ResponseEntity update(@RequestBody List<SupplierQualificationBaseDTO> supplierQualificationBaseDTOS) {
        supplierQualificationLogic.update(supplierQualificationBaseDTOS);
        return ResponseEntity.ok().build();
    }

    @PostMapping("remove")
    public ResponseEntity remove(Long id) {
        supplierQualificationLogic.removeById(id);
        return ResponseEntity.ok().build();
    }

}
