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.GameAuthGroupAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.GameAuthGroupListParam;
import com.zanxiang.game.module.manage.pojo.params.GameAuthRoleGroupAddParam;
import com.zanxiang.game.module.manage.pojo.params.GameAuthRoleGroupListParam;
import com.zanxiang.game.module.manage.pojo.vo.GameAuthGroupVO;
import com.zanxiang.game.module.manage.pojo.vo.GameAuthRoleGroupVO;
import com.zanxiang.game.module.manage.service.IGameAuthGroupService;
import com.zanxiang.game.module.manage.service.IGameAuthRoleGroupService;
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 : 2024-05-21
 * @description : 角色授权分组
 */
@RestController
@RequestMapping("/game/auth/group")
@Slf4j
public class GameAuthGroupController {

    @Autowired
    private IGameAuthGroupService gameAuthGroupService;

    @Autowired
    private IGameAuthRoleGroupService gameAuthRoleGroupService;

    @PostMapping(value = "/listOfPage")
    @PreAuthorize(permissionKey = "manage:gameAuthGroup:listOfPage")
    public ResultVO<IPage<GameAuthGroupVO>> listOfPage(@Validated @RequestBody GameAuthGroupListParam param) {
        return ResultVO.ok(gameAuthGroupService.listOfPage(param));
    }

    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:gameAuthGroup:addOrUpdate")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameAuthGroupAddUpdateParam param) {
        return ResultVO.ok(gameAuthGroupService.addOrUpdate(param));
    }

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

    @PostMapping(value = "/role/listOfPage")
    @PreAuthorize(permissionKey = "manage:gameAuthGroupRole:listOfPage")
    public ResultVO<IPage<GameAuthRoleGroupVO>> list(@Validated @RequestBody GameAuthRoleGroupListParam param) {
        return ResultVO.ok(gameAuthRoleGroupService.listOfPage(param));
    }

    @PutMapping(value = "/role/leader/update")
    @PreAuthorize(permissionKey = "manage:gameAuthGroupRole:leaderUpdate")
    public ResultVO<Boolean> leaderUpdate(@RequestParam Long groupId, @RequestParam Long userId, @RequestParam Boolean isLeader) {
        return ResultVO.ok(gameAuthRoleGroupService.leaderUpdate(groupId, userId, isLeader));
    }

    @PostMapping(value = "/role/add")
    @PreAuthorize(permissionKey = "manage:gameAuthGroupRole:add")
    public ResultVO<Boolean> add(@Validated @RequestBody GameAuthRoleGroupAddParam param) {
        return ResultVO.ok(gameAuthRoleGroupService.groupAddUser(param));
    }

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