package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.GameRemitLogListParam;
import com.zanxiang.game.module.manage.pojo.params.OrderParam;
import com.zanxiang.game.module.manage.pojo.params.PayCallCpLogParam;
import com.zanxiang.game.module.manage.pojo.vo.GameRemitLogVO;
import com.zanxiang.game.module.manage.pojo.vo.LogPayCpVO;
import com.zanxiang.game.module.manage.pojo.vo.OrderListVO;
import com.zanxiang.game.module.manage.service.IGameRemitLogService;
import com.zanxiang.game.module.manage.service.ILogPayCpService;
import com.zanxiang.game.module.manage.service.IOrderService;
import com.zanxiang.module.util.pojo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author : lingfeng
 * @time : 2022-11-07
 * @description : 订单
 */
@Api(tags = "订单模块接口")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private ILogPayCpService logPayCpService;

    @Autowired
    private IGameRemitLogService gameRemitLogService;

    @ApiOperation(value = "订单列表")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:order:orderList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = OrderListVO.class, responseContainer = "list")})
    public ResultVO<OrderListVO> orderList(@Validated @RequestBody OrderParam param) {
        return ResultVO.ok(orderService.orderList(param));
    }

    @ApiOperation(value = "订单回调CP列表")
    @PostMapping(value = "/cp/call/list")
    @PreAuthorize(permissionKey = "manage:order:callCpList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = LogPayCpVO.class, responseContainer = "list")})
    public ResultVO<IPage<LogPayCpVO>> callCpList(@Validated @RequestBody PayCallCpLogParam param) {
        return ResultVO.ok(logPayCpService.callCpList(param));
    }

    @ApiOperation(value = "订单Excel下载")
    @PostMapping(value = "/list/excel")
    @PreAuthorize(permissionKey = "manage:order:orderExcel")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功")})
    public void getOrderExcel(@Validated @RequestBody OrderParam param, HttpServletResponse response) {
        orderService.getOrderExcel(param, response);
    }

    @ApiOperation(value = "游戏提现记录")
    @PostMapping(value = "/remit/Log")
    @PreAuthorize(permissionKey = "manage:order:remitLog")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameRemitLogVO.class, responseContainer = "list")})
    public ResultVO<IPage<GameRemitLogVO>> listOfPage(@Validated @RequestBody GameRemitLogListParam param) {
        return ResultVO.ok(gameRemitLogService.listOfPage(param));
    }

    @ApiOperation(value = "订单通知CP手动")
    @GetMapping(value = "/call/cp")
    @PreAuthorize(permissionKey = "manage:order:callCp")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> callCp(@RequestParam String orderId, String payKey) {
        return ResultVO.ok(orderService.callCp(orderId, payKey));
    }
}
