package ink.wgink.login.oauth2.client.controller.apis.user;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.component.SecurityComponent;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.oauth2.client.service.user.IUserService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.vos.UpdatePasswordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: UserController
 * @Description: 用户
 * @Author: WangGeng
 * @Date: 2021/1/24 17:10
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "用户")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/user")
public class UserController extends DefaultBaseController {

    @Autowired
    private IUserService userService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "修改密码", notes = "修改密码接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update-password")
    @CheckRequestBodyAnnotation
    public SuccessResult updatePassword(@RequestBody UpdatePasswordVO updatePasswordVO) {
        userService.updatePassword(updatePasswordVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "获取密码状态", notes = "获取密码状态接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get-password-status")
    public SuccessResultData<String> getPasswordStatus() {
        return userService.getPasswordStatus(securityComponent.getCurrentUser().getUserId());
    }

}
