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

import com.zanxiang.game.module.sdk.annotation.ValidLogin;
import com.zanxiang.game.module.sdk.pojo.param.BackLogMediaSdkParam;
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.IGameBackLogMediaSdkService;
import com.zanxiang.game.module.sdk.service.IGameService;
import com.zanxiang.module.util.JsonUtil;
import com.zanxiang.module.util.pojo.ResultVO;
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 : 回传相关接口
 */
@RestController
@Slf4j
@RequestMapping(value = "/api/ad/back")
public class CallBackController {

    @Autowired
    private IGameService gameService;

    @Autowired
    private IGameBackLogMediaSdkService backLogMediaSdkService;

    @GetMapping("/ad/sdk/config")
    public ResultVO<Map<String, Object>> getAdSdkConfig(UserData userData) {
        Map<String, Object> adSdkConfigMap = gameService.getAdSdkConfig(userData);
        log.error("媒体初始化配置返回, map : {}, userId : {}", JsonUtil.toString(adSdkConfigMap), userData.getUserId());
        return ResultVO.ok(adSdkConfigMap);
    }

    @PostMapping("/call/judge")
    public ResultVO<Map<String, Object>> callBackJudge(@Validated @RequestBody CallBackControlParam param,
                                                       @ValidLogin UserData userData) {
        log.error("事件回传判断请求, param : {},  userId : {}", JsonUtil.toString(param), userData.getUserId());
        Map<String, Object> resultMap = backLogMediaSdkService.callBackJudge(param, userData);
        log.error("事件回传判断结果, param : {},  userId : {}, resultMap : {}", JsonUtil.toString(param),
                userData.getUserId(), JsonUtil.toString(resultMap));
        return ResultVO.ok(resultMap);
    }

    @PostMapping("/add/log")
    public ResultVO<Boolean> addMediaSdkBackLog(@Validated @RequestBody BackLogMediaSdkParam param,
                                                @ValidLogin UserData userData) {
        log.error("媒体sdk执行回传日志提交, param : {},  userId : {}", JsonUtil.toString(param), userData.getUserId());
        return ResultVO.ok(backLogMediaSdkService.addMediaSdkBackLog(param, userData));
    }
}
