package com.jy.system.controller;

import com.jy.framework.model.annotation.JyLog;
import com.jy.framework.model.enums.BusinessType;
import com.jy.system.model.dto.EditPwdDto;
import com.jy.system.model.dto.LoginDto;
import com.jy.system.model.dto.UserInfoDto;
import com.jy.system.model.vo.CaptchaImageVo;
import com.jy.system.model.vo.LoginInfoVo;
import com.jy.system.model.vo.UserInfoVo;
import com.jy.system.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthController {

    @Resource
    private AuthService authService;

    /**
     * 获取验证码
     */
    @GetMapping("/getCaptchaImage")
    public CaptchaImageVo getCaptchaImage() {
        return authService.getCaptchaImage();
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public LoginInfoVo login(@Validated @RequestBody LoginDto dto) {
        return authService.login(dto);
    }

    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public void logout() {
        authService.logout();
    }

    /**
     * 获取登录信息
     */
    @GetMapping("/getLoginInfo")
    public LoginInfoVo getLoginInfo() {
        return authService.getLoginInfo();
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/getUserInfo")
    public UserInfoVo getUserInfo() {
        return authService.getUserInfo();
    }

    /**
     * 修改用户信息
     */
    @JyLog(title = "修改用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editUserInfo")
    public void editUserInfo(@Validated @RequestBody UserInfoDto dto) {
        authService.editUserInfo(dto);
    }

    /**
     * 修改用户密码
     */
    @JyLog(title = "用户修改密码", businessType = BusinessType.UPDATE, excludeFields = {"oldPwd", "newPwd"})
    @PostMapping("/editPwd")
    public void editPwd(@Validated @RequestBody EditPwdDto dto) {
        authService.editPwd(dto);
    }

}
