package beilv.stadium.controller;

import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.utils.uuid.IdUtils;
import beilv.stadium.domain.Stadium;
import beilv.stadium.domain.StadiumBO;
import beilv.stadium.service.IStadiumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/stadium")
public class StadiumController extends BaseController {

    @Autowired
    private IStadiumService stadiumService;



    /**
     * 添加订单
     * 写入订单信息: 下单人id, 订单编号, 下单时间, 支付状态:待支付
     * 调用者传递参数: 用户id, 联系人, 联系电话, 赛事id, 订单类型,
     */
    @PostMapping("/toBeStadium")
    public AjaxResult addStadium(@RequestBody Stadium stadium) {
        return toAjax(stadiumService.toBeStadium(stadium));
    }

    /**
     * 通过订单id取消订单
     * 调用者传递参数: 订单id,
     * 注:  取消订单时在下单后没有支付时, 可以执行的操作. 如果已经支付了, 则需要调用申请退款接口
     */
    @PostMapping("/cancellStadium")
    public AjaxResult cancellStadium(@RequestBody Stadium stadium){
        return toAjax(stadiumService.cancellStadium(stadium));
    }

    /**
     * 查询订单
     * 调用者传递参数: 用户id, 订单状态, 订单类型
     */
    @GetMapping("/getStadiumList")
    public AjaxResult getStadiumList(StadiumBO stadiumBO){
        return AjaxResult.success(stadiumService.getStadiumList(stadiumBO));
    }

    /**
     * 支付回调
     * 调用着传递: 订单编号, 支付状态
     */
    @PostMapping("/havePaidStadium")
    public AjaxResult havePaidStadium(@RequestBody Stadium stadium){
        return toAjax(stadiumService.havePaidStadium(stadium));
    }

    /**
     * 退款回调
     * 调用者传递参数: 订单id, 用户id
     */
    @PostMapping("/refundStadium")
    public AjaxResult refundStadium(@RequestBody Stadium stadium){
        return toAjax(stadiumService.refundStadium(stadium));
    }

    /**
     * 支付验证
     * 支付之前调用方法, 检测是否可以进行支付
     * @return Boolean  true: 可以支付; false: 不可以支付
     */
    @PostMapping("/paymentVerification")
    public Boolean paymentVerification(@RequestBody Stadium stadium){
        return stadiumService.paymentVerification(stadium);
    }
}
