package com.czg.controller.admin;

import com.czg.log.annotation.OperationLog;
import com.czg.order.dto.CreditBuyerOrderDTO;
import com.czg.order.dto.CreditPaymentRecordDTO;
import com.czg.order.entity.CreditPaymentRecord;
import com.czg.order.param.CreditBuyerOrderQueryParam;
import com.czg.order.param.CreditPaymentRecordQueryParam;
import com.czg.order.service.CreditBuyerOrderService;
import com.czg.order.service.CreditPaymentRecordService;
import com.czg.order.vo.CreditBuyerOrderSummaryVo;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 挂账账单
 *
 * @author Tankaikai tankaikai@aliyun.com
 * @since 1.0 2025-03-04
 */
@AllArgsConstructor
@RestController
@RequestMapping("/admin/order/credit")
public class CreditBuyerOrderController {
    private final CreditBuyerOrderService creditBuyerOrderService;
    private final CreditPaymentRecordService creditPaymentRecordService;

    /**
     * 分页
     */
    @GetMapping("/buyerOrder/page")
    @OperationLog("挂账账单-分页")
    //@SaAdminCheckPermission("creditBuyerOrder:page")
    public CzgResult<Page<CreditBuyerOrderDTO>> getCreditBuyerOrderPage(CreditBuyerOrderQueryParam param) {
        Page<CreditBuyerOrderDTO> data = creditBuyerOrderService.getCreditBuyerOrderPage(param);
        return CzgResult.success(data);
    }

    /**
     * 付款
     */
    @PostMapping("/buyerOrder/pay")
    @OperationLog("挂账账单-付款")
    //@SaAdminCheckPermission("creditBuyerOrder:pay")
    public CzgResult<Void> pay(@RequestBody CreditPaymentRecord record) {
        creditBuyerOrderService.pay(record);
        return CzgResult.success();
    }

    /**
     * 统计
     */
    @GetMapping("/buyerOrder/summary")
    @OperationLog("挂账账单-统计")
    //@SaAdminCheckPermission("creditBuyerOrder:summary")
    public CzgResult<CreditBuyerOrderSummaryVo> summary(CreditBuyerOrderQueryParam param) {
        CreditBuyerOrderSummaryVo data = creditBuyerOrderService.summary(param);
        return CzgResult.success(data);
    }

    /**
     * 挂账账单付款记录分页
     */
    @GetMapping("/paymentRecord/page")
    @OperationLog("挂账账单付款记录-分页")
    //@SaAdminCheckPermission("creditPaymentRecord:page")
    public CzgResult<Page<CreditPaymentRecordDTO>> getCreditPaymentRecordPage(CreditPaymentRecordQueryParam param) {
        Page<CreditPaymentRecordDTO> data = creditPaymentRecordService.getCreditPaymentRecordPage(param);
        return CzgResult.success(data);
    }

}