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

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 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
@RestController
@RequestMapping("/api/game/gift/pack")
public class GameGiftPackApi {

    @Autowired
    private IGameGiftPackLinkLogService gameGiftPackLinkLogService;

    @Autowired
    private IGameGiftPackCodeLogService gameGiftPackCodeLogService;

    @PostMapping(value = "/link/log/push")
    public ResultVO<Long> linkList(@Validated @RequestBody GameGiftPackLinkLogPushParam param) {
        return ResultVO.ok(gameGiftPackLinkLogService.linkVisitLogPush(param.getUrl()));
    }

    @GetMapping(value = "/game/source/server")
    public ResultVO<Map<String, String>> getSourceGameServer(@RequestParam Long linkLogId) {
        return ResultVO.ok(gameGiftPackLinkLogService.getSourceGameServerByLinkLogId(linkLogId));
    }

    @GetMapping(value = "/role/check")
    public ResultVO<Map<String, Object>> gameUserRoleCheck(@RequestParam Long linkLogId, @RequestParam String serverId,
                                                           @RequestParam String roleName) {
        return ResultVO.ok(gameGiftPackLinkLogService.gameUserRoleCheck(linkLogId, serverId, roleName));
    }

    @GetMapping(value = "/phone/code/send")
    public ResultVO<Boolean> randomCodeSend(@RequestParam Long linkLogId, @RequestParam String phoneNumber) {
        return ResultVO.ok(gameGiftPackLinkLogService.randomCodeSend(linkLogId, phoneNumber));
    }

    @GetMapping(value = "/code/send")
    public ResultVO<Map<String, Object>> codeSend(@RequestParam Long linkLogId, @RequestParam String userPhone,
                                                  @RequestParam String randomCode) {
        return ResultVO.ok(gameGiftPackCodeLogService.getGiftPackCode(linkLogId, userPhone, randomCode));
    }
}
