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 jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

    @Autowired
    private ICpPushDataService cpPushDataService;

    @Autowired
    private IGameRemitLogService gameRemitLogService;

    @Autowired
    private IUserVisitLogService userVisitLogService;

    @UnSignCheck
    @PostMapping("/remit/log/push")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameRemitLogParam param) {
        return ResultVO.ok(gameRemitLogService.addOrUpdate(param));
    }

    @UnSignCheck
    @PostMapping("/visit/log/push")
    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
    @PostMapping("/cp/push/user")
    public ResultVO<CpPushUserVO> cpPushUser(@RequestParam String gameId, @Validated @RequestBody CpPushUserParam param) {
        return ResultVO.ok(cpPushDataService.pushUser(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @PostMapping("/cp/push/role")
    public ResultVO<CpPushResultVO> cpPushRole(@RequestParam String gameId, @Validated @RequestBody CpPushRoleParam param) {
        return ResultVO.ok(cpPushDataService.pushRole(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @PostMapping("/cp/push/order")
    public ResultVO<CpPushResultVO> cpPushOrder(@RequestParam String gameId, @Validated @RequestBody CpPushOrderParam param) {
        return ResultVO.ok(cpPushDataService.pushOrder(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @PostMapping("/cp/push/server")
    public ResultVO<CpPushResultVO> cpPushServer(@RequestParam String gameId, @Validated @RequestBody CpPushServerParam param) {
        return ResultVO.ok(cpPushDataService.pushServer(gameId, param));
    }

    @UnSignCheck
    @PushDataCheck
    @PostMapping("/cp/push/active")
    public ResultVO<CpPushResultVO> cpPushActive(@RequestParam String gameId, @Validated @RequestBody CpPushActiveParam param) {
        return ResultVO.ok(cpPushDataService.pushActive(gameId, param));
    }

}
