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 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 : 游戏管理接口
 */
@RestController
@RequestMapping("/game")
@Slf4j
public class GameController {

    @Autowired
    private IGameService gameService;

    @Autowired
    private IGameAppletService gameAppletService;

    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:game:add")
    public ResultVO<Boolean> gameAddOrUpdate(@Validated @RequestBody GameAddParam param) {
        return ResultVO.ok(gameService.gameAddOrUpdate(param));
    }

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:game:list")
    public ResultVO<IPage<GameListVO>> gameList(@Validated @RequestBody GameListParam param) {
        return ResultVO.ok(gameService.gameList(param));
    }

    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:game:delete")
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(gameService.deleteById(id));
    }

    @PatchMapping(value = "/status/update")
    @PreAuthorize(permissionKey = "manage:game:statusUpdate")
    public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
        return ResultVO.ok(gameService.statusUpdate(id, status));
    }

    @PutMapping(value = "/create/game/action/set")
    @PreAuthorize(permissionKey = "manage:game:createGameActionSet")
    public ResultVO<Boolean> createActionSet(@RequestParam Long gameId) {
        return ResultVO.ok(gameAppletService.createActionSet(gameId));
    }
}
