package com.qmth.exam.reserve.controller.admin;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.boot.core.collection.PageResult;
import com.qmth.exam.reserve.bean.login.LoginUser;
import com.qmth.exam.reserve.bean.user.UserReq;
import com.qmth.exam.reserve.bean.user.UserSaveReq;
import com.qmth.exam.reserve.bean.user.UserVO;
import com.qmth.exam.reserve.controller.BaseController;
import com.qmth.exam.reserve.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "【管理端】用户相关接口")
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin/user")
@Aac(strict = false, auth = true)
public class UserController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户管理分页")
    @PostMapping(value = "/page")
    public PageResult<UserVO> page(@RequestBody UserReq req) {
        return userService.pageUser(req);
    }

    @ApiOperation(value = "用户新增、编辑")
    @PostMapping(value = "/save")
    public void save(@RequestBody UserSaveReq req) {
        LoginUser user = curLoginUser();
        userService.saveUser(user, req);
    }

    @ApiOperation(value = "用户信息")
    @PostMapping(value = "/info")
    public UserVO info(@ApiParam("用户ID") @RequestParam Long id) {
        return userService.info(id);
    }

    @ApiOperation(value = "用户重置密码")
    @PostMapping(value = "/reset/password")
    public void resetPassword(@ApiParam("用户ID") @RequestParam Long id) {
        userService.resetPassword(id);
    }

    @ApiOperation(value = "用户启用、禁用")
    @PostMapping(value = "/enable")
    public void enable(@ApiParam("用户ID") @RequestParam Long id, @ApiParam("启用、禁用") @RequestParam Boolean enable) {
        userService.enable(id, enable);
    }

}
