package cn.reghao.tnb.file.app.zorder.controller;

import cn.reghao.jutil.jdk.web.result.Result;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.auth.AuthUser;
import cn.reghao.tnb.file.app.zorder.model.vo.OrderDetail;
import cn.reghao.tnb.file.app.zorder.service.OrderService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2024-04-16 10:54:52
 */
@Tag(name = "订单接口")
@RestController
@RequestMapping("/api/mall/order")
public class OrderController {
    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @AuthUser
    @Operation(summary = "取消订单", description = "N")
    @PostMapping("/cancel/{orderId}")
    public String cancelOrder(@PathVariable("orderId") Long orderId) {
        return WebResult.success();
    }

    @Operation(summary = "订单退款", description = "N")
    @AuthUser
    @PostMapping("/refund/{orderId}")
    public String refund(@PathVariable("orderId") Long orderId) {
        return WebResult.success();
    }

    @AuthUser
    @Operation(summary = "获取订单列表", description = "N")
    @GetMapping("")
    public String getOrders() {
        List<OrderDetail> list = orderService.getOrders(1);
        return WebResult.success(list);
    }

    @AuthUser
    @Operation(summary = "获取订单详情", description = "N")
    @GetMapping("/{orderId}")
    public String getOrderDetail(@PathVariable("orderId") Long orderId) {
        OrderDetail orderDetail = orderService.getOrderDetail(orderId);
        return WebResult.success(orderDetail);
    }

    @Operation(summary = "支付订单", description = "N")
    @AuthUser
    @PostMapping("/pay/{orderId}")
    public String payOrder(@PathVariable("orderId") Long orderId) {
        Result result = orderService.payOrder(orderId);
        return WebResult.result(result);
    }
}
