package com.zanxiang.game.data.serve.controller;

import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.data.serve.pojo.dto.*;
import com.zanxiang.game.data.serve.pojo.vo.RoleChatDetailVO;
import com.zanxiang.game.data.serve.pojo.vo.RoleChatVO;
import com.zanxiang.game.data.serve.pojo.vo.RoleGameCountryVO;
import com.zanxiang.game.data.serve.service.IRoleManageService;
import com.zanxiang.game.data.serve.utils.Page;
import com.zanxiang.game.module.base.ServerInfo;
import com.zanxiang.game.module.base.pojo.vo.SendMsgResultVO;
import com.zanxiang.game.module.base.pojo.vo.SendMsgVO;
import com.zanxiang.game.module.base.rpc.ICPSendMsgRpc;
import com.zanxiang.module.util.pojo.ResultVO;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author tianhua
 * @time 2023/9/8
 * @Description  角色运营管理控制层接口
 **/
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleManageController {

    @Autowired
    private IRoleManageService roleManageService;
    @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
    private ICPSendMsgRpc sendMsgRpc;


    @PreAuthorize(permissionKey = "roleManage:recharge:role")
    @PostMapping("/rechargeRanking")
    public ResultVO<Page<Map>> getRoleRechargeRanking(@RequestBody RoleRechargeRankingDTO dto) {
        return ResultVO.ok(roleManageService.getRoleRechargeRanking(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:combat:role")
    @PostMapping("/combatRanking")
    public ResultVO<Page<Map>> getRoleCombatRanking(@RequestBody RoleCombatRankingDTO dto) {
        return ResultVO.ok(roleManageService.getRoleCombatRanking(dto));
    }


    @PreAuthorize(permissionKey = "roleManage:level:listOfPage")
    @PostMapping("/level/listOfPage")
    public ResultVO<Page<Map>> levelListOfPage(@RequestBody RoleLevelParamDTO dto) {
        return ResultVO.ok(roleManageService.levelListOfPage(dto));
    }




    @PreAuthorize(permissionKey = "roleManage:ipInfo:listOfPage")
    @PostMapping("/ipInfo/listOfPage")
    public ResultVO<Page<Map>> ipInfoListOfPage(@RequestBody RoleIpInfoParamDTO dto) {
        return ResultVO.ok(roleManageService.ipInfoListOfPage(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:ipInfo:list")
    @PostMapping("/roleIpDetail/list")
    public ResultVO<List<Map>> roleIpDetailListOfPage(@RequestBody RoleIpInfoParamDTO dto) {
        return ResultVO.ok(roleManageService.roleIpDetailListOfPage(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:ipRoleDetail:list")
    @PostMapping("/roleDetailList")
    public ResultVO<List<Map>> roleDetailList(@RequestBody RoleIpInfoParamDTO dto) {
        return ResultVO.ok(roleManageService.roleDetailList(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:ipRoleDetail:list")
    @PostMapping("/suspectedRoleDetailList")
    public ResultVO<List<Map>> suspectedRoleDetailList(@RequestBody RoleIpInfoParamDTO dto) {
        return ResultVO.ok(roleManageService.suspectedRoleDetailList(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:userDetail:list")
    @PostMapping("/userDetail/list")
    public ResultVO<List<Map>> userDetailList(@RequestBody RoleIpInfoParamDTO dto) {
        return ResultVO.ok(roleManageService.userDetailList(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:gameCountry:list")
    @PostMapping("/gameCountryList")
    public ResultVO<List<Map>> gameCountryList(@RequestBody GameCountryParamDTO dto) {
        return ResultVO.ok(roleManageService.gameCountryList(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:gameCountry:dataList")
    @PostMapping("/gameCountryDataList")
    public ResultVO<Map<String, List<RoleGameCountryVO>>> gameCountryDataList(@Valid @RequestBody GameCountryParamDTO dto) {
        return ResultVO.ok(roleManageService.gameCountryDataList(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:gameCountryRole:list")
    @PostMapping("/gameCountryRoleList")
    public ResultVO<Page<Map>> gameCountryRoleList(@Valid @RequestBody RoleGameCountryParamDTO dto) {
        return ResultVO.ok(roleManageService.gameCountryRoleList(dto));
    }



    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:create")
    @PostMapping("/sendMsgTask")
    public ResultVO createSendMsgTask(@RequestBody @Valid SendMsgTaskDTO dto) {
        roleManageService.createSendMsgTask(dto);
        return ResultVO.ok("操作成功", true);
    }

    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:list")
    @PostMapping("/sendMsgTask/list")
    public ResultVO<Page<SendMsgVO>> getSendMsgTaskList(@RequestBody MsgTaskDTO dto) {
        return ResultVO.ok(roleManageService.getSendMsgTaskList(dto));
    }


    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:resultList")
    @PostMapping("/sendMsgTask/resultList")
    public ResultVO<Page<SendMsgResultVO>> getSendMsgResultList(@RequestBody @Valid MsgTaskResultDTO msgTaskResultDto) {
        return ResultVO.ok(roleManageService.getSendMsgResultList(msgTaskResultDto));
    }

    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:reSendMsgByTaskId")
    @PostMapping("/reSendMsgByTaskId")
    public ResultVO<Boolean> reSendMsgByTaskId(@RequestParam("gameId") Long gameId,@RequestParam("taskId") Long taskId) {
        return sendMsgRpc.reSendMsgByTaskId(gameId, taskId);
    }

    @PreAuthorize(permissionKey = "roleManage:sendMsgTask:reSendMsgByResultId")
    @PostMapping("/reSendMsgByResultId")
    public ResultVO<Boolean> reSendMsgByResultId(@RequestParam("resultId") Long resultId) {
        return sendMsgRpc.reSendMsgByResultId(resultId);
    }

    @PreAuthorize(permissionKey = "roleManage:chat:listOfPage")
    @PostMapping("/chatListOfPage")
    public ResultVO<Page<RoleChatVO>> chatListOfPage(@RequestBody RoleChatParamDTO dto) {
        return ResultVO.ok(roleManageService.chatListOfPage(dto));
    }

    @PreAuthorize(permissionKey = "roleManage:chatDetail:listOfPage")
    @PostMapping("/chatDetailListOfPage")
    public ResultVO<Page<RoleChatDetailVO>> chatDetail(@RequestBody RoleChatDetailParamDTO dto) {
        return ResultVO.ok(roleManageService.chatDetail(dto));
    }

}
