package io.wdd.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.wdd.common.response.R;
import io.wdd.server.beans.po.ServerRolePO;
import io.wdd.server.beans.vo.ServerRoleVO;
import io.wdd.server.coreService.CoreRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api("Octopus Server - 服务器角色信息")
@RequestMapping("/role")
public class RoleController {

    @Resource
    CoreRoleService roleService;

    @GetMapping("/all")
    @ApiOperation("角色-获取全部角色信息")
    public R<List<ServerRolePO>> roleGetAll(
    ) {
        return R.ok(roleService.roleGetAll());
    }

    @PostMapping("/create")
    @ApiOperation("角色-创建一个角色")
    public R<String> roleCreate(
            @RequestBody ServerRoleVO serverRoleVO
    ) {

        String result = "创建角色成功！";
        if (!roleService.roleCreate(serverRoleVO)) {
            result = "创建角色失败！";
        }
        return R.ok(result);
    }

    @PostMapping("/update")
    @ApiOperation("角色-更新一个角色")
    public R<String> roleUpdate(
            @RequestBody ServerRolePO serverRolePO
    ) {

        String result = "更新角色成功！";
        if (!roleService.roleUpdate(serverRolePO)) {
            result = "更新角色失败！";
        }
        return R.ok(result);
    }

    @PostMapping("/delete")
    @ApiOperation("角色-删除一个角色")
    public R<String> roleDelete(
            @RequestParam(value = "roleId", name = "roleId") @ApiParam(value = "roleId") Long roleId
    ) {

        String result = "删除角色成功！";
        if (!roleService.roleDelete(roleId)) {
            result = "删除角色失败！";
        }
        return R.ok(result);
    }


}
