package org.dromara.main.controller;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.bo.CsOrderCardBo;
import org.dromara.main.domain.vo.CsOrderCardVo;
import org.dromara.main.service.ICsOrderCardService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/main/order-card")
public class CsOrderCardController extends BaseController {

    private final ICsOrderCardService orderCardService;

    /**
     * 发送结算单
     */
    @Log(title = "发送结算单", businessType = BusinessType.INSERT)
    @PostMapping("/send")
    public R<CsOrderCardVo> sendOrderCard(@Validated @RequestBody CsOrderCardBo bo) {
        return R.ok(orderCardService.sendOrderCard(bo));
    }

    /**
     * 查询结算单状态
     */
    @GetMapping("/{orderCardId}")
    public R<CsOrderCardVo> getInfo(@PathVariable Long orderCardId) {
        return R.ok(orderCardService.queryById(orderCardId));
    }

    /**
     * 用户支付结算单
     */
    @Log(title = "支付结算单", businessType = BusinessType.UPDATE)
    @PostMapping("/{orderCardId}/pay")
    public R<Void> payOrderCard(@PathVariable Long orderCardId, @RequestParam Long userId) {
        return toAjax(orderCardService.payOrderCard(orderCardId, userId));
    }

    /**
     * 取消结算单
     */
    @Log(title = "取消结算单", businessType = BusinessType.UPDATE)
    @PutMapping("/{orderCardId}/cancel")
    public R<Void> cancelOrderCard(@PathVariable Long orderCardId) {
        return toAjax(orderCardService.cancelOrderCard(orderCardId));
    }
}
