package com.sonic.lion.controller.web;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.lion.domain.req.CheckoutReq;
import com.sonic.lion.domain.req.TradeQueryReq;
import com.sonic.lion.domain.resp.CheckoutResp;
import com.sonic.lion.domain.resp.QueryResp;
import com.sonic.lion.service.CashierService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收银台
 * @author: code
 * @date: 2025/05/20
 * @Description:
 * @version: 1.0.0
 */
@Slf4j
@RestController
public class CashierController {

    @Autowired
    private CashierService cashierService;

    @ApiOperation(value = "结账", tags = "收银台")
    @PostMapping("/web/pay/cashier/checkout")
    public Result<CheckoutResp> checkout(@RequestBody @Validated CheckoutReq req, @ApiParam(hidden = true) Session session) throws Exception {
        return Result.success(cashierService.checkout(session.getUserId(), req));
    }

    @ApiOperation(value = "结账结果查询", tags = "收银台")
    @PostMapping("/web/pay/cashier/query")
    public Result<QueryResp> query(@RequestBody TradeQueryReq req) {
        return cashierService.query(req);
    }

}
