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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.GameMergeServerParam;
import com.zanxiang.game.module.manage.pojo.params.GameServerAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.GameServerListParam;
import com.zanxiang.game.module.manage.pojo.vo.GameServerListVO;
import com.zanxiang.game.module.manage.pojo.vo.GameServerVO;
import com.zanxiang.game.module.manage.pojo.vo.GameSupperVO;
import com.zanxiang.game.module.manage.service.IGameServerService;
import com.zanxiang.game.module.manage.service.IGameSupperService;
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.List;

/**
 * @author : lingfeng
 * @time : 2023-08-07
 * @description : 游戏区服接口
 */
@Api(tags = {"游戏区服接口"})
@RestController
@RequestMapping("/gameServer")
@Slf4j
public class GameServerController {

    @Autowired
    private IGameServerService gameServerService;

    @Autowired
    private IGameSupperService gameSupperService;

    @ApiOperation(value = "新增或修改游戏区服")
    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:gameServer:addOrUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameServerAddUpdateParam param) {
        return ResultVO.ok(gameServerService.addOrUpdate(param));
    }

    @ApiOperation(value = "游戏区服列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:gameServer:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameServerListVO.class)})
    public ResultVO<IPage<GameServerListVO>> listOfPage(@Validated @RequestBody GameServerListParam param) {
        return ResultVO.ok(gameServerService.listOfPage(param));
    }

    @ApiOperation(value = "游戏区服删除")
    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:gameServer:delete")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(gameServerService.deleteById(id));
    }

    @ApiOperation(value = "合服新增修改")
    @PostMapping(value = "/merge/add/or/update")
    @PreAuthorize(permissionKey = "manage:gameServer:mergeAddOrUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> mergeServerAddUpdate(@Validated @RequestBody GameMergeServerParam param) {
        return ResultVO.ok(gameServerService.mergeServerAddUpdate(param));
    }

    @ApiOperation(value = "获取合服超父游戏列表")
    @GetMapping(value = "/game/supper/list")
    @PreAuthorize(permissionKey = "manage:gameServer:gameSupperList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameSupperVO.class)})
    public ResultVO<List<GameSupperVO>> getGameSupperList() {
        return ResultVO.ok(gameSupperService.getGameSupperList());
    }

    @ApiOperation(value = "获取未参与合服的区服列表")
    @GetMapping(value = "/unMerge/server/list")
    @PreAuthorize(permissionKey = "manage:gameServer:unMergeServer")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameServerVO.class)})
    public ResultVO<List<GameServerVO>> unMergeServerList(@RequestParam Long gameId) {
        return ResultVO.ok(gameServerService.getServerList(gameId, Boolean.FALSE));
    }

    @ApiOperation(value = "获取所有区服列表(无分页)")
    @GetMapping(value = "/all/server/list")
    @PreAuthorize(permissionKey = "manage:gameServer:allServer")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameServerVO.class)})
    public ResultVO<List<GameServerVO>> allServerList(@RequestParam Long gameId) {
        return ResultVO.ok(gameServerService.getServerList(gameId, null));
    }
}
