package com.hz.pm.api.user.controller;


import com.hz.pm.api.user.manage.UserInfoManage;
import com.hz.pm.api.user.model.po.ReqUserDetailEditPO;
import com.hz.pm.api.user.model.po.ReqUserDisableOrEnablePO;
import com.hz.pm.api.user.model.po.UserDetailReq;
import com.hz.pm.api.user.model.po.UserInfoListReq;
import com.hz.pm.api.user.model.vo.ResUserDetailVO;
import com.hz.pm.api.user.model.vo.UserInfoListVO;
import com.hz.pm.api.user.model.vo.UserRoleVO;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Liuxinxin
 * @since 2023-01-04
 */
@RestController
@RequestMapping("/api/v1/user-info")
@RequiredArgsConstructor
@Api(tags = "用户管理")
public class UserInfoController {

    private final UserInfoManage userInfoManage;

    @ApiOperation(value = "用户列表搜索", notes = "用户列表搜索")
    @PostMapping("/list")
    public PageVo<UserInfoListVO> userInfoList(@Valid @RequestBody UserInfoListReq req) {
        return userInfoManage.list(req);
    }

    @ApiOperation(value = "用户禁用/启用", notes = "用户禁用/启用")
    @PostMapping("/disable-enable")
    public void disableOrEnable(@Valid @RequestBody ReqUserDisableOrEnablePO req) {
        userInfoManage.disableOrEnable(req);
    }

    @ApiOperation(value = "用户详情", notes = "用户详情")
    @PostMapping("/detail")
    public ResUserDetailVO userInfoDetail(@Valid @RequestBody UserDetailReq req) {
        return userInfoManage.userInfoDetail(req);
    }

    @ApiOperation(value = "用户详情编辑", notes = "用户详情编辑")
    @PostMapping("/detail/edit")
    @WebLog("用户详情编辑")
    public void userInfoDetailEdit(@Valid @RequestBody ReqUserDetailEditPO req) {
        userInfoManage.userInfoDetailEdit(req);
    }

    @ApiOperation(value = "获取当前登陆用户详情信息", notes = "用户详情")
    @PostMapping("/current-user-info")
    public ResUserDetailVO currentUserInfo() {
        return userInfoManage.currentUserInfo();
    }

    @ApiOperation(value = "获取当前用户可控角色列表")
    @PostMapping("/controlled/role-list")
    public List<UserRoleVO> getControlledRoleList() {
        return userInfoManage.getControlledRoleList();
    }
}
