package com.ads.business.controller;

import com.ads.business.service.AdmUserService;
import com.ads.business.service.model.request.AdmUserListRequest;
import com.ads.business.service.model.request.EditUserRequest;
import com.ads.business.service.model.request.ResetPasswordRequest;
import com.ads.business.service.model.request.UpdateSwitchRequest;
import com.ads.common.data.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Return
 * @Author hou
 * @Date 2021/10/25 9:17
 * @Destription
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class AdmUserController {

    @Resource
    private AdmUserService admUserService;

    @GetMapping("/list")
    @ApiOperation("用户列表")
    public JsonResult list(AdmUserListRequest request) {
        return admUserService.list(request);
    }

    @PostMapping("/add")
    @ApiOperation("新增用户")
    JsonResult add(@RequestBody @Valid EditUserRequest request) {
        return admUserService.add(request);
    }


    /**
     * 获取用户详情
     *
     * @param userId 用户ID
     * @return 返回结果信息
     */
    @ApiOperation(value = "获取用户详情", notes = "获取用户详情")
    @GetMapping(value = "/detail")
    JsonResult detail(@RequestParam(value = "id", required = true) Long userId) {
        return admUserService.detail(userId);
    }


    /**
     * 状态修改
     *
     * @param request 修改状态入参
     * @return JsonResult
     */
    @PutMapping("/updateSwitch")
    @ApiOperation(value = "状态修改", notes = "状态修改")
    public JsonResult updateSwitch(@RequestBody @Valid UpdateSwitchRequest request) {
        return admUserService.updateSwitch(Long.valueOf(request.getId()), request.getStatus());
    }

    /**
     * 重置密码
     *
     * @param request 重置密码入参
     * @return JsonResult
     */
    @PutMapping("/resetPassword")
    @ApiOperation(value = "重置密码", notes = "重置密码")
    public JsonResult resetPassword(@RequestBody @Valid ResetPasswordRequest request) {
        return admUserService.resetPassword(request);
    }

    @PostMapping("/update")
    @ApiOperation("修改用户")
    JsonResult update(@RequestBody @Valid EditUserRequest request) {
        return admUserService.update(request);
    }
}
