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

import com.github.sd4324530.jtuple.Tuple2;
import com.zanxiang.game.module.manage.pojo.params.GameGiftPackLinkLogPushParam;
import com.zanxiang.game.module.manage.service.IGameGiftPackCodeLogService;
import com.zanxiang.game.module.manage.service.IGameGiftPackLinkLogService;
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-11-04
 * @description : 发码器外部接口
 */
@Slf4j
@Api(tags = {"发码器H5接口"})
@RestController
@RequestMapping("/api/game/gift/pack")
public class GameGiftPackApi {

    @Autowired
    private IGameGiftPackLinkLogService gameGiftPackLinkLogService;

    @Autowired
    private IGameGiftPackCodeLogService gameGiftPackCodeLogService;

    @ApiOperation(value = "链接访问记录推送提交")
    @PostMapping(value = "/link/log/push")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Long.class)})
    public ResultVO<Long> linkList(@Validated @RequestBody GameGiftPackLinkLogPushParam param) {
        return ResultVO.ok(gameGiftPackLinkLogService.linkVisitLogPush(param.getUrl()));
    }

    @ApiOperation(value = "获取游戏区服列表")
    @GetMapping(value = "/game/source/server")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Long.class)})
    public ResultVO<Map<String, String>> getSourceGameServer(@RequestParam Long linkLogId) {
        return ResultVO.ok(gameGiftPackLinkLogService.getSourceGameServerByLinkLogId(linkLogId));
    }

    @ApiOperation(value = "游戏玩家角色验证")
    @GetMapping(value = "/role/check")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Long.class)})
    public ResultVO<Map<String, Object>> gameUserRoleCheck(@RequestParam Long linkLogId, @RequestParam String serverId,
                                                           @RequestParam String roleName) {
        return ResultVO.ok(gameGiftPackLinkLogService.gameUserRoleCheck(linkLogId, serverId, roleName));
    }

    @ApiOperation(value = "手机验证码发送")
    @GetMapping(value = "/phone/code/send")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> randomCodeSend(@RequestParam Long linkLogId, @RequestParam String phoneNumber) {
        return ResultVO.ok(gameGiftPackLinkLogService.randomCodeSend(linkLogId, phoneNumber));
    }

    @ApiOperation(value = "领取礼包码")
    @GetMapping(value = "/code/send")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Tuple2.class)})
    public ResultVO<Map<String, Object>> codeSend(@RequestParam Long linkLogId, @RequestParam String userPhone,
                                                  @RequestParam String randomCode) {
        return ResultVO.ok(gameGiftPackCodeLogService.getGiftPackCode(linkLogId, userPhone, randomCode));
    }
}
