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

import com.zanxiang.game.module.sdk.annotation.PushDataCheck;
import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
import com.zanxiang.game.module.sdk.pojo.param.*;
import com.zanxiang.game.module.sdk.pojo.vo.CpPushResultVO;
import com.zanxiang.game.module.sdk.pojo.vo.CpPushUserVO;
import com.zanxiang.game.module.sdk.service.ICpPushDataService;
import com.zanxiang.game.module.sdk.service.IGameRemitLogService;
import com.zanxiang.game.module.sdk.service.IUserVisitLogService;
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.HttpServletRequest;

/**
 * @author : lingfeng
 * @time : 2023-07-17
 * @description : 消息推送接收
 */
@Api(tags = "消息推送接收接口")
@RestController
@RequestMapping(value = "/api")
public class PushController {

    @Autowired
    private ICpPushDataService cpPushDataService;

    @Autowired
    private IGameRemitLogService gameRemitLogService;

    @Autowired
    private IUserVisitLogService userVisitLogService;

    @UnSignCheck
    @ApiOperation(value = "游戏提现记录日志推送")
    @PostMapping("/remit/log/push")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameRemitLogParam param) {
        return ResultVO.ok(gameRemitLogService.addOrUpdate(param));
    }

    @UnSignCheck
    @ApiOperation(value = "用户下载地址访问记录")
    @PostMapping("/visit/log/push")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> visitLogCreate(@Validated @RequestBody UserVisitLogParam param,
                                            @RequestHeader(name = "User-Agent") String userAgent,
                                            HttpServletRequest httpServletRequest) {
        return ResultVO.ok(userVisitLogService.visitLogCreate(param.getUrl(), userAgent, httpServletRequest));
    }

    @UnSignCheck
    @PushDataCheck
    @ApiOperation(value = "玩家注册 / 登录信息推送")
    @PostMapping("/cp/push/user")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<CpPushUserVO> cpPushUser(@RequestParam String gameId, @Validated @RequestBody CpPushUserParam param) {
        return ResultVO.ok(cpPushDataService.pushUser(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @ApiOperation(value = "玩家角色信息推送")
    @PostMapping("/cp/push/role")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<CpPushResultVO> cpPushRole(@RequestParam String gameId, @Validated @RequestBody CpPushRoleParam param) {
        return ResultVO.ok(cpPushDataService.pushRole(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @ApiOperation(value = "玩家订单信息推送")
    @PostMapping("/cp/push/order")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<CpPushResultVO> cpPushOrder(@RequestParam String gameId, @Validated @RequestBody CpPushOrderParam param) {
        return ResultVO.ok(cpPushDataService.pushOrder(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @ApiOperation(value = "开服信息推送")
    @PostMapping("/cp/push/server")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<CpPushResultVO> cpPushServer(@RequestParam String gameId, @Validated @RequestBody CpPushServerParam param) {
        return ResultVO.ok(cpPushDataService.pushServer(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @ApiOperation(value = "玩家活跃信息推送")
    @PostMapping("/cp/push/active")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<CpPushResultVO> cpPushActive(@RequestParam String gameId, @Validated @RequestBody CpPushActiveParam param) {
        return ResultVO.ok(cpPushDataService.pushActive(gameId, param));
    }

}
