package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.common.base.BaseController;
import com.community.huiju.service.IToSysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/")
@Api(value = "运营角色 API", description = "运营角色 API")
public class SysRoleController extends BaseController {

    @Autowired
    private IToSysRoleService iToSysRoleService;

    @RequestMapping(value = "/role/list", method = RequestMethod.POST)
    @ApiOperation(value = "获取所有角色", notes = "获取所有角色")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "pageNum第几页;pageSize一页多少行;roleName角色名称(可选)")
    })
    public ResponseBean getRoleAll(@RequestBody String parameter,
                                   HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        responseBean = iToSysRoleService.getAll(parameter);
        return responseBean;
    }

    @RequestMapping(value = "/role/add", method = RequestMethod.POST)
    @ApiOperation(value = "添加角色", notes = "添加角色")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "header", name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "roleName角色名称;description描述;menuArray菜单id集合")
    })
    public ResponseBean addRole(@RequestBody String parameter,
                                   HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iToSysRoleService.addRole(parameter, userElement);
        return responseBean;
    }

    @RequestMapping(value = "/role/info/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "根据角色id获取详情", notes = "根据角色ID回去详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "角色id")
    })
    public ResponseBean getInfo(@PathVariable("id") Integer id,
                                HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        responseBean = iToSysRoleService.getInfo(id);
        return responseBean;
    }


    @RequestMapping(value = "/role/update", method = RequestMethod.PUT)
    @ApiOperation(value = "修改角色", notes = "修改角色")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "header", name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "id角色编号;roleName角色名称;description描述;menuArray菜单id集合")
    })
    public ResponseBean updateRole(@RequestBody String parameter,
                                HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iToSysRoleService.updateRole(parameter, userElement);
        return responseBean;
    }

    @RequestMapping(value = "/role/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "header", name = "X-Auth-Token", value = "Token"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "id角色编号集合")
    })
    public ResponseBean deleteRole(@RequestBody List<Integer> parameter, HttpSession session){
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iToSysRoleService.deleteRole(parameter, userElement);

        return responseBean;
    }

}
