package com.ruoyi.web.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.vipOrder.domain.VipOrderQuery;
import com.ruoyi.bst.vipOrder.domain.dto.VipOrderCreateDTO;
import com.ruoyi.bst.vipOrder.service.VipOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/app/vipOrder")
public class AppVipOrderController extends BaseController{

    @Autowired
    private VipOrderService vipOrderService;

    @ApiOperation("查询本人卡券订单")
    @GetMapping("/list")
    public TableDataInfo list(VipOrderQuery query) {
        startPage();
        startOrderBy();
        query.setUserId(getUserId());
        return getDataTable(vipOrderService.selectVipOrderList(query));
    }

    @ApiOperation("查询本人卡券订单详情")
    @GetMapping("/detail")
    public AjaxResult detail(Long id) {
        return success(vipOrderService.selectDetailByUserId(id, getUserId()));
    }

    @ApiOperation("下单并支付卡券订单")
    @PostMapping
    @Log(title = "下单并支付卡券订单", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.VIP_ORDER)
    public AjaxResult createOrder(@RequestBody @Validated VipOrderCreateDTO dto) {
        dto.setUserId(getUserId());
        return success(vipOrderService.createOrder(dto));
    }
    
}
