package com.sckw.payment.controller;

import com.sckw.core.web.response.HttpResult;
import com.sckw.payment.model.constant.SettlementOrderTypeEnum;
import com.sckw.payment.model.constant.SettlementWalletPayTypeEnum;
import com.sckw.payment.model.vo.req.OfflinePaymentReq;
import com.sckw.payment.model.vo.req.SettlementWalletReq;
import com.sckw.payment.model.vo.req.WalletPayReq;
import com.sckw.payment.service.KwpSettlementWalletService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 结算-电子钱包结算记录（交易订单结算/物流订单结算）
 *
 * @author Aick Spt
 * @date 2023-07-20 14:42
 */
@Validated
@RestController
@RequestMapping(name = "结算-电子钱包结算记录", path = "/kwpSettlementWallet")
public class KwpSettlementWalletController {

    //  =========  物流付款  =========

    @Resource
    private KwpSettlementWalletService kwpSettlementWalletService;

    @PostMapping(name = "物流-电子钱包付款（货到付款）结算记录-列表", path = "pageListLogisticsPayment")
    public HttpResult pageListLogisticsPayment(@RequestBody @Valid SettlementWalletReq settlementWalletReq) {
        settlementWalletReq.setPayType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
        settlementWalletReq.setOrderType(SettlementOrderTypeEnum.LOGISTICS.getStatus());
        return HttpResult.ok(kwpSettlementWalletService.pageListLogisticsPayment(settlementWalletReq));
    }

//    @GetMapping(name = "物流-电子钱包付款（货到付款）结算记录-详情", path = "detailLogisticsPayment")
//    public HttpResult detailLogisticsPayment(@RequestParam("id") Long id) {
////        return HttpResult.ok(kwpSettlementWalletService.detailLogisticsPayment(id));
//        return HttpResult.ok(null);
//    }

    /**
     * @author Aick Spt
     * @date 2023-07-25 09:55
     */
    @PostMapping(name = "物流-电子钱包付款（货到付款）结算记录-新增", path = "confirmLogisticsPayment")
    public HttpResult confirmLogisticsPayment(@RequestBody @Valid OfflinePaymentReq offlinePaymentReq) {
        return HttpResult.ok(kwpSettlementWalletService.confirmLogisticsPayment(offlinePaymentReq));
    }


    /**
     * 运费-货到付款-查询钱包余额
     *
     * @param id 结算单id
     * @author Aick Spt
     * @date 2023-08-16 11:15
     */
    @GetMapping(name = "运费-货到付款-查询钱包余额", path = "getConfirmLogisticsPay")
    public HttpResult getConfirmLogisticsPay(@RequestParam("id") @NotBlank(message = "id不能为空") String id) {
        return HttpResult.ok(kwpSettlementWalletService.getConfirmLogisticsPayment(Long.parseLong(id)));
    }


    //  =========  销售收付款  =========

    /**
     * 采购付款记录-货到付款查询列表
     *
     * @param settlementWalletReq
     * @return
     */
    @GetMapping(name = "销售-付款记录列表（采购电子钱包结算记录）", path = "pageListTradePayment")
    public HttpResult pageListTradePayment(@Valid SettlementWalletReq settlementWalletReq) {
        settlementWalletReq.setPayType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
        settlementWalletReq.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
        return HttpResult.ok(kwpSettlementWalletService.pageList(settlementWalletReq));
    }

    /**
     * 采购-货到付款-查询钱包余额
     *
     * @param id 结算单id
     * @author Aick Spt
     * @date 2023-07-25 09:55
     */
    @GetMapping(name = "采购-货到付款-查询钱包余额", path = "getConfirmPay")
    public HttpResult getConfirmPay(@RequestParam("id") @NotBlank(message = "id不能为空") String id) {
        return HttpResult.ok(kwpSettlementWalletService.getConfirmTradePayment(Long.parseLong(id)));
    }

    /**
     * 采购-货到付款
     */
    @PostMapping(name = "采购-付款确认-(新增电子钱包记录-采购货到付款)", path = "confirmReceive")
    public HttpResult confirmTradePayment(@RequestBody @Valid WalletPayReq payReq) {
        return HttpResult.ok(kwpSettlementWalletService.confirmTradePayment(payReq));
    }

    /**
     * 销售收款记录-预付款查询列表
     *
     * @param settlementWalletReq
     * @return
     */
    @GetMapping(name = "销售-收款记录列表-预付款(电子钱包)", path = "pageListTradeCollection")
    public HttpResult pageListTradeCollection(@Valid SettlementWalletReq settlementWalletReq) {
        settlementWalletReq.setPayType(SettlementWalletPayTypeEnum.ADVANCE_PAYMENT.getStatus());
        settlementWalletReq.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
        return HttpResult.ok(kwpSettlementWalletService.pageList(settlementWalletReq));
    }

    /**
     * 销售-预付款
     *
     * @param id 结算单id
     * @author Aick Spt
     * @date 2023-07-25 09:55
     */
    @PostMapping(name = "销售-收款确认-预付款(电子钱包)", path = "confirmPrePay")
    public HttpResult confirmTradeCollection(@RequestParam("id") @NotBlank(message = "id不能为空") String id) {
        return HttpResult.ok(kwpSettlementWalletService.confirmTradeCollection(Long.parseLong(id)));
    }


}
