package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.entity.main.TsmRole;
import com.crunii.micro.service.sysmgr.dto.sysmgr.*;
import com.crunii.micro.service.sysmgr.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 田平 create 2023-02-20 03:19:02
 */
@Api(value = "角色相关")
@Controller
@Slf4j
@RequestMapping("/auth/RoleController")
public class RoleController {

	private final RoleService roleService;

	public RoleController(RoleService roleService) {
		this.roleService = roleService;
	}

	@ApiOperation(value = "角色分页")
	@RequestMapping(path = "/pageRole", method = RequestMethod.POST)
	@ResponseBody
	public Result<PageRsp<RoleResp>> pageRole(@RequestBody @ApiParam PageReq<RoleReq> req) {
		log.info("req:" + req.toString());
		Result<PageRsp<RoleResp>> result = new Result<>();
		result.setData(roleService.pageRole(req));
		return result;
	}

	@ApiOperation(value = "角色列表查询")
	@RequestMapping(path = "/listRole", method = RequestMethod.POST)
	@ResponseBody
	public Result<List<TsmRole>> listRole(@RequestBody @ApiParam RoleReq req) {
		log.info("req:" + req.toString());
		Result<List<TsmRole>> result = new Result<>();
		result.setData(roleService.selectRoleList(req));
		return result;
	}

	@ApiOperation(value = "创建角色")
	@RequestMapping(path = "/createRole", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> createRole(@Validated @RequestBody @ApiParam RoleC roleC) {
		Result<String> result = new Result<>();
		roleService.createRole(roleC);
		return result;
	}

	@ApiOperation(value = "更新角色")
	@RequestMapping(path = "/updateRole", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> updateRole(@RequestBody @ApiParam RoleU roleU) {
		Result<String> result = new Result<>();
		roleService.updateRole(roleU);
		return result;
	}

	@ApiOperation(value = "获取角色列表")
	@RequestMapping(path = "/getRoleList", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<RoleListRspVo>> getRoleList(@RequestParam("roleName")String roleName) {
		Result<List<RoleListRspVo>> result = new Result<>();
		result.setData(roleService.getRoleList(roleName));
		return result;
	}

}
