package com.yida.data.mall.controller.h5;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.mall.dto.h5.CreateBillOrderDTO;
import com.yida.data.mall.dto.h5.H5BillInfoDTO;
import com.yida.data.mall.dto.h5.H5BillOrderPageDTO;
import com.yida.data.mall.dto.h5.H5BillSelectDTO;
import com.yida.data.mall.service.H5EduBillService;
import com.yida.data.mall.vo.h5.BillPayInfoVO;
import com.yida.data.mall.vo.h5.H5BillOrderInfoVO;
import com.yida.data.mall.vo.h5.H5BillOrderPageVO;
import com.yida.data.mall.vo.h5.H5BillSelectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 缴费账单前端 Controller
 *
 * @author ZYJ
 * @date 2022-3-30 19:40:02
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("h5/eduBill")
@Api(tags = "缴费账单前端接口api")
public class H5EduBillController {

    private final H5EduBillService h5EduBillService;

    @PostMapping("/listH5Bill")
    @ApiOperation("查询前台账单列表")
    public ResultBean<List<H5BillSelectVO>> listH5Bill(@RequestBody H5BillSelectDTO h5BillSelectDTO) {
        return ResultBean.buildSuccess(h5EduBillService.listH5Bill(h5BillSelectDTO));
    }

    @PostMapping("/getH5BillInfo")
    @ApiOperation("查询前台账单详情")
    public ResultBean<H5BillSelectVO> getH5BillInfo(@RequestBody H5BillInfoDTO h5BillInfoDTO) {
        return ResultBean.buildSuccess(h5EduBillService.getH5BillInfo(h5BillInfoDTO));
    }

    @PostMapping("/createBillOrder")
    @ApiOperation("生成账单订单")
    public ResultBean<BillPayInfoVO> createBillOrder(@RequestBody CreateBillOrderDTO createBillOrderDTO) {
        return ResultBean.buildSuccess(h5EduBillService.createBillOrder(createBillOrderDTO));
    }

    @GetMapping("/billOrderSuccess")
    @ApiOperation("账单订单完成(前台支付完成后调用)")
    public ResultBean<String> billOrderSuccess(
            @ApiParam(value = "订单号", required = true) @RequestParam String orderCode) {
        h5EduBillService.billOrderSuccess(orderCode);
        return ResultBean.buildSuccess();
    }

    @PostMapping(value = "listH5BillOrderPage")
    @ApiOperation(value = "前端查询账单订单列表数据")
    public ResultBean<IPage<H5BillOrderPageVO>> listH5BillOrderPage(@RequestBody H5BillOrderPageDTO h5BillOrderPageDTO) {
        IPage<H5BillOrderPageVO> page = h5EduBillService.listH5BillOrderPage(h5BillOrderPageDTO);
        return ResultBean.buildSuccess(page);
    }

    @GetMapping(value = "getH5BillOrderInfo")
    @ApiOperation(value = "前端查询账单订单详情")
    public ResultBean<H5BillOrderInfoVO> getH5BillOrderInfo(
            @ApiParam(value = "账单订单id") @RequestParam(required = false) Long billOrderId,
            @ApiParam(value = "订单号") @RequestParam(required = false) String orderCode) {
        return ResultBean.buildSuccess(h5EduBillService.getH5BillOrderInfo(billOrderId, orderCode));
    }

    @GetMapping("continuePayOrder")
    @ApiOperation("继续支付")
    public ResultBean<BillPayInfoVO> continuePayOrder(
            @ApiParam(value = "订单号", required = true) @RequestParam String orderCode,
            @ApiParam(value = "学校id", required = true) @RequestParam Long deptId) {
        BillPayInfoVO infoVO = h5EduBillService.continuePayOrder(orderCode, deptId);
        return ResultBean.buildSuccess(infoVO);
    }

    @GetMapping(value = "cancelOrder")
    @ApiOperation(value = "取消订单")
    public ResultBean<String> cancelOrder(
            @ApiParam(value = "订单号", required = true) @RequestParam String orderCode) {
        h5EduBillService.cancelOrder(orderCode);
        return ResultBean.buildSuccess();
    }

    @GetMapping(value = "refundOrder")
    @ApiOperation(value = "缴费账单退款")
    public ResultBean<String> refundOrder(
            @ApiParam(value = "订单号", required = true) @RequestParam String orderCode) {
        h5EduBillService.refundOrder(orderCode);
        return ResultBean.buildSuccess();
    }

    @GetMapping(value = "checkExistOrder")
    @ApiOperation(value = "查看是否存在待支付的订单")
    public ResultBean<String> checkExistOrder(
            @ApiParam(value = "账单id", required = true) @RequestParam Long billId,
            @ApiParam(value = "学生id", required = true) @RequestParam Long studentId) {
        return ResultBean.buildSuccess(h5EduBillService.checkExistOrder(billId, studentId));
    }
}
