package com.sckw.auth.controller;

import com.sckw.auth.model.vo.req.*;
import com.sckw.auth.service.IAuthService;
import com.sckw.core.exception.SystemException;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 用户权限
 * @author: czh
 * @date: 2023/6/19
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private IAuthService authService;

    /**
     * @param reqVo 登录入参
     * @return HttpResult
     * @desc: 用户登录
     * @author: czh
     * @date: 2023/6/16
     */
    @PostMapping("/login")
    public HttpResult login(@Valid @RequestBody LoginReqVo reqVo,
                            @RequestHeader(name = "Client-Type", required = true) String clientType,
                            @RequestHeader(name = "System-Type", required = true) int systemType) throws SystemException {
        reqVo.setSystemType(systemType);
        reqVo.setClientType(clientType);
        return HttpResult.ok(authService.login(reqVo));
    }

    /**
     * @param reqVo 注册
     * @return HttpResult
     * @desc: 用户注册
     * @author: czh
     * @date: 2023/6/16
     */
    @PostMapping("/register")
    public HttpResult register(@Valid @RequestBody RegisterReqVo reqVo,
                               @RequestHeader(name = "System-Type", required = true) int systemType) throws SystemException {
        reqVo.setSystemType(systemType);
        authService.register(reqVo);
        return HttpResult.ok(HttpStatus.MSG_007);
    }

    /**
     * @param reqVo 忘记密码入参
     * @return HttpResult
     * @desc: 忘记密码
     * @author: czh
     * @date: 2023/6/19
     */
    @PostMapping("/forgetPassword")
    public HttpResult forgetPassword(@Valid @RequestBody ForgetPasswordReqVo reqVo,
                                     @RequestHeader(name = "System-Type", required = true) int systemType) throws SystemException {
        reqVo.setSystemType(systemType);
        authService.forgetPassword(reqVo);
        return HttpResult.ok(HttpStatus.MSG_002);
    }

    /**
     * @param {password 旧密码、newPassword 新密码、account 账号}
     * @description 修改密码
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/updatePassword")
    public HttpResult updatePassword(@Valid @RequestBody UpdatePasswordReqVo reqVo,
                                     @RequestHeader(name = "System-Type", required = true) int systemType) {
        reqVo.setSystemType(systemType);
        authService.updatePassword(reqVo);
        return HttpResult.ok(HttpStatus.MSG_002);
    }

    /**
     * @param id 主键ID
     * @description 重置密码
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/resetPassword")
    public HttpResult resetPassword(@RequestParam Long id) {
        authService.resetPassword(id);
        return HttpResult.ok(HttpStatus.MSG_001);
    }

    /**
     * @desc: 获取验证码
     * @param: reqVo 入参
     * @author: czh
     * @date 2023/7/23
     * @return HttpResult
     */
    @PostMapping("getRegisterSms")
    public HttpResult getRegisterSms(@Valid @RequestBody GetRegisterSmsReqVo reqVo,
                                   @RequestHeader(name = "System-Type", required = true) int systemType) {
        reqVo.setSystemType(systemType);
        return HttpResult.ok(authService.getRegisterSms(reqVo));
    }

}