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

import com.zanxiang.game.module.sdk.annotation.ValidLogin;
import com.zanxiang.game.module.sdk.pojo.param.CallBackControlParam;
import com.zanxiang.game.module.sdk.pojo.param.UserData;
import com.zanxiang.game.module.sdk.service.ICallBackService;
import com.zanxiang.game.module.sdk.service.IGameService;
import com.zanxiang.module.util.JsonUtil;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author : lingfeng
 * @time : 2024-06-26
 * @description : 回传相关接口
 */
@Api(tags = "回传控制相关接口")
@RestController
@Slf4j
@RequestMapping(value = "/api/ad/back")
public class CallBackController {

    @Autowired
    private IGameService gameService;

    @Autowired
    private ICallBackService callBackService;

    @ApiOperation(value = "获取游戏广告媒体回传sdk配置")
    @GetMapping("/ad/sdk/config")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Map.class)})
    public ResultVO<Map<String, Object>> getAdSdkConfig(UserData userData) {
        return ResultVO.ok(gameService.getAdSdkConfig(userData));
    }

    @ApiOperation(value = "判断事件是否回传")
    @PostMapping("/call/judge")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Map<String, Object>> callBackJudge(@Validated @RequestBody CallBackControlParam param, @ValidLogin UserData userData) {
        ResultVO<Map<String, Object>> ok = ResultVO.ok(callBackService.callBackJudge(param, userData));
        log.error("事件回传判断结果, param : {}, 返回结果 ok : {}", JsonUtil.toString(param), JsonUtil.toString(ok));
        return ok;
    }
}
