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.GameAddParam;
import com.zanxiang.game.module.manage.pojo.params.GameListParam;
import com.zanxiang.game.module.manage.pojo.vo.GameListVO;
import com.zanxiang.game.module.manage.service.IGameAppletService;
import com.zanxiang.game.module.manage.service.IGameService;
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.*;

/**
 * @author : lingfeng
 * @time : 2022-06-30
 * @description : 游戏管理接口
 */
@Api(tags = {"游戏管理接口"})
@RestController
@RequestMapping("/game")
@Slf4j
public class GameController {

    @Autowired
    private IGameService gameService;

    @Autowired
    private IGameAppletService gameAppletService;

    @ApiOperation(value = "新增游戏")
    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:game:add")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameListVO.class)})
    public ResultVO<Boolean> gameAddOrUpdate(@Validated @RequestBody GameAddParam param) {
        return ResultVO.ok(gameService.gameAddOrUpdate(param));
    }

    @ApiOperation(value = "游戏列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:game:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameListVO.class)})
    public ResultVO<IPage<GameListVO>> gameList(@Validated @RequestBody GameListParam param) {
        return ResultVO.ok(gameService.gameList(param));
    }

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

    @ApiOperation(value = "游戏状态变更")
    @PatchMapping(value = "/status/update")
    @PreAuthorize(permissionKey = "manage:game:statusUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameListVO.class)})
    public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
        return ResultVO.ok(gameService.statusUpdate(id, status));
    }

    @ApiOperation(value = "创建游戏回传数据源")
    @PutMapping(value = "/create/game/action/set")
    @PreAuthorize(permissionKey = "manage:game:createGameActionSet")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> createActionSet(@RequestParam Long gameId) {
        return ResultVO.ok(gameAppletService.createActionSet(gameId));
    }
}
