package com.sckw.contract.controller;

import com.sckw.contract.api.model.dto.res.ContractLogisticsOrderResDto;
import com.sckw.contract.api.model.dto.res.ContractTradeOrderDto;
import com.sckw.contract.api.model.dto.res.ContractTradeOrderInfo;
import com.sckw.contract.api.model.dto.res.LogisticsOrderDto;
import com.sckw.contract.model.vo.req.*;
import com.sckw.contract.model.vo.res.ContractDetailResp;
import com.sckw.contract.model.vo.res.ContractStatusCountResp;
import com.sckw.contract.model.vo.res.QueryListResVo;
import com.sckw.contract.service.operateService.KwcContractTradeService;
import com.sckw.core.model.enums.EntTypeEnum;
import com.sckw.core.model.page.PageResult;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.BaseResult;
import com.sckw.core.web.response.HttpResult;
import com.sckw.core.web.response.result.PageDataResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author czh
 * @desc 销售合同
 * @date 2023/7/13
 */
@RestController
@RequestMapping("kwcSale")
@RequiredArgsConstructor
@Tag(name = "贸易合同相关接口")
public class KwcContractSaleController {

    private final KwcContractTradeService kwcContractTradeService;

    /**
     * @desc: 分页查询
     * @param: reqVo 分页入参
     * @author: sky
     * @date 2023/7/17
     * @return HttpResult
     */
    @PostMapping("/queryListByPage")
    @Operation(summary = "分页查询贸易合同")
    public BaseResult<PageResult> queryListByPage(@RequestBody QueryListReqVo reqVo) {
        //reqVo.setEntType(EntTypeEnum.SUPPLIER.getCode());
        return BaseResult.success(kwcContractTradeService.queryListByPage(reqVo));
    }

    /**
     * @desc: 分页查询
     * @param: reqVo 分页入参
     * @author: sky
     * @date 2023/7/17  如果上面不能用可以用这个
     * @return HttpResult
     */
    @PostMapping("/queryTradeListByPage")
    @Operation(summary = "分页查询贸易合同")
    public BaseResult<PageDataResult<QueryListResVo>> queryTradeListByPage(@RequestBody QueryTradeReq req) {
        //reqVo.setEntType(EntTypeEnum.SUPPLIER.getCode());
        return null;
    }


    /**
     * @param reqVo 新增入参
     * @return HttpResult
     * @desc: 新增贸易合同
     * @author: sky
     * @date: 2023/7/18
     */
    @PostMapping("/addTradeContract")
    @Operation(summary = "新增贸易合同")
    public BaseResult<String> addTradeContract(@Valid @RequestBody ContractTradeReqVo reqVo) {
        kwcContractTradeService.addTradeContract(reqVo);
        return BaseResult.success(HttpStatus.MSG_003);
    }

    /**
     * @param req 新增入参
     * @return HttpResult
     * @desc: 新增补充合同
     * @author: sky
     * @date: 2023/7/18
     */
    @PostMapping("/addSupplyTradeContract")
    @Operation(summary = "补充合同")
    public BaseResult<String> addSupplyTradeContract(@Valid @RequestBody SupplyContractTradeReq req) {
        kwcContractTradeService.addSupplyTradeContract(req);
        return BaseResult.success(HttpStatus.MSG_003);
    }

    /**
     * @param reqVo 补充入参
     * @desc: 补充合同
     * @author: czh
     * @date: 2023/7/14
     */
    @PostMapping("supplement")
    public HttpResult supplement(@Valid @RequestBody ContractTradeReqVo reqVo) {
        kwcContractTradeService.supplement(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @desc: 合同详情
     * @param reqVo id
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("detail")
    public HttpResult detail(@Valid @RequestBody IdReqVo reqVo) {
        return HttpResult.ok(kwcContractTradeService.detail(reqVo.getId()));
    }


    /**
     * @desc: 发起签约
     * @param reqVo id
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("submit")
    public HttpResult submit(@Valid @RequestBody ContractTradeReqVo reqVo) {
        return HttpResult.ok(kwcContractTradeService.submit(reqVo));
    }

    /**
     * @desc: 修改草稿
     * @param reqVo id
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("/updateTradeContract")
    @Operation(summary = "修改贸易合同")
    public BaseResult<String> updateTradeContract(@Valid @RequestBody ContractTradeReqVo reqVo) {
        kwcContractTradeService.update(reqVo);
        return BaseResult.success();
    }


    /**
     * @desc: 手动完结
     * @param reqVo ids
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("complete")
    public HttpResult complete(@Valid @RequestBody CompleteReqVo reqVo) {
        kwcContractTradeService.complete(reqVo);
        return HttpResult.ok();
    }


    /**
     * @desc: 删除
     * @param reqVo ids
     * @author: czh
     * @date 2023/7/16
     * @return HttpResult
     */
    @PostMapping("delete")
    public HttpResult delete(@Valid @RequestBody IdsReqVo reqVo) {
        kwcContractTradeService.delete(reqVo.getIds());
        return HttpResult.ok();
    }


    /**
     * @desc: 导出
     * @param reqVo 查询入参
     * @author: czh
     * @date 2023/7/17
     */
    @PostMapping(value = "export", produces = MediaType.APPLICATION_JSON_VALUE)
    public void export(@Valid @RequestBody QueryListReqVo reqVo, HttpServletResponse response) {
        reqVo.setEntType(EntTypeEnum.SUPPLIER.getCode());
        kwcContractTradeService.export(reqVo, response);
    }

    /**
     * @return HttpResult
     * @desc: 查询当前企业的销售合同
     * @author: czh
     * @date: 2023/7/18
     */
    @PostMapping("queryCurrentEntSaleContractList")
    public HttpResult queryCurrentEntSaleContractList() {
        return HttpResult.ok(kwcContractTradeService.queryCurrentEntSaleContractList());
    }

    /**
     * @return HttpResult
     * @desc: 分组查询
     * @author: czh
     * @date: 2023/7/18
     */
    @PostMapping("findListGroup")
    public HttpResult findListGroup(@RequestBody QueryListReqVo reqVo) {
        reqVo.setEntType(EntTypeEnum.SUPPLIER.getCode());
        return HttpResult.ok(kwcContractTradeService.findListGroup(reqVo));
    }


    /**
     * @param reqVo 分页查询
     * @return HttpResult
     * @desc: 运营端查贸易合同
     * @author: czh
     * @date: 2023/9/13
     */
    @PostMapping("queryTradeByPage")
    public HttpResult queryTradeByPage(@RequestBody QueryListReqVo reqVo) {
        return HttpResult.ok(kwcContractTradeService.queryTradeByPage(reqVo));
    }

    /**
     * @return HttpResult
     * @desc: 分组查询
     * @author: czh
     * @date: 2023/7/18
     */
    @PostMapping("findTradeListGroup")
    public HttpResult findTradeListGroup(@RequestBody QueryListReqVo reqVo) {
        return HttpResult.ok(kwcContractTradeService.findTradeListGroup(reqVo));
    }

    /**
     * @param reqVo 查询参数
     * @desc: 运营端查贸易合同导出
     * @author: czh
     * @date: 2023/9/13
     */
    @PostMapping(value = "/exportTradeList", produces = MediaType.APPLICATION_JSON_VALUE)
    public void exportTradeList(@RequestBody QueryListReqVo reqVo, HttpServletResponse response) {
        kwcContractTradeService.exportTradeList(reqVo, response);
    }

    /**
     * 修改合同状态 （审核，手动完结）
     */
    @PostMapping("/updateStatus")
    @Operation(summary = "审批完结贸易合同")
    public BaseResult<Boolean> updateStatus(@Valid @RequestBody ApprovalReq req) {
        return BaseResult.success(kwcContractTradeService.updateStatus(req));
    }

    /**
     * 查询合同详情
     */

    @PostMapping("/queryContractDetail")
    @Operation(summary = "查询贸易合同详情")
    public BaseResult<ContractDetailResp> queryContractDetail(@Valid @RequestBody ContractDetailReq req) {
        return BaseResult.success(kwcContractTradeService.queryContractDetail(req));
    }

    /**
     * 查询物流合同
     */
    @PostMapping("/queryContractLogisticsOrder")
    @Operation(summary = "查询物流合同")
    public BaseResult<List<ContractLogisticsOrderResDto>> queryContractLogisticsOrder(@Valid @RequestBody LogisticsOrderDto req) {
        return BaseResult.success(kwcContractTradeService.queryContractLogisticsOrder(req));
    }
    /**
     * 查询贸易合同
     */
    @PostMapping("/queryContractTradeOrder")
    @Operation(summary = "查询贸易合同")
    public BaseResult<List<ContractTradeOrderInfo>> queryContractTradeOrder(@Valid @RequestBody ContractTradeOrderDto req) {
        return BaseResult.success(kwcContractTradeService.queryContractTradeOrder(req));
    }
    /**
     * 贸易合同状态统计
     */
    @PostMapping("/queryTradeContractStatusCount")
    @Operation(summary = "贸易合同状态统计")
    public BaseResult<ContractStatusCountResp> queryTradeContractStatusCount(@RequestBody QueryListReqVo req) {
        return BaseResult.success(kwcContractTradeService.queryTradeContractStatusCount(req));
    }
}
