package com.m2pool.lease.controller;


import com.m2pool.common.security.annotation.RequiresLogin;
import com.m2pool.lease.annotation.Decrypt;
import com.m2pool.lease.annotation.LoginRequired;
import com.m2pool.lease.dto.Result;
import com.m2pool.lease.dto.v2.GoogleInfoDto;
import com.m2pool.lease.service.LeaseUserService;
import com.m2pool.lease.vo.EmailCodeVo;
import com.m2pool.lease.vo.UserLoginVo;
import com.m2pool.lease.vo.UserRegisterVo;
import com.m2pool.lease.vo.v2.GoogleBindVo;
import com.m2pool.lease.vo.v2.GoogleCloseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yyb
 * @since 2025-07-23
 */
@Api(tags = "用户授权控制器")
@LoginRequired(value = false)
@RestController
@RequestMapping("/auth")
public class LeaseAuthController {

    @Resource
    private LeaseUserService leaseUserService;

    @Decrypt
    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public Result<Map<String, Object>> login(@RequestBody UserLoginVo userLoginVo){
        return leaseUserService.login(userLoginVo);
    }


    @Decrypt
    @PostMapping("/register")
    @ApiOperation(value = "用户注册")
    public Result<String> register(@RequestBody UserRegisterVo userRegisterVo){
        return leaseUserService.register(userRegisterVo);
    }

    @Decrypt
    @PostMapping("/updatePassword")
    @ApiOperation(value = "修改密码")
    public Result<String> updatePassword(@RequestBody UserLoginVo userLoginVo){
        return leaseUserService.updatePassword(userLoginVo);
    }


    @PostMapping("/logout")
    @ApiOperation(value = "登出")
    public Result<String> logout(){
        return leaseUserService.logout();
    }

    @PostMapping("/sendLoginCode")
    @ApiOperation(value = "发送用户登录邮箱验证码")
    public Result<String> sendLoginCode(@RequestBody @Valid EmailCodeVo emailCodeVo){
        return leaseUserService.sendLoginCode(emailCodeVo);
    }

    @PostMapping("/sendRegisterCode")
    @ApiOperation(value = "发送用户注册邮箱验证码")
    public Result<String> sendRegisterCode(@RequestBody @Valid EmailCodeVo emailCodeVo){
        return leaseUserService.sendRegisterCode(emailCodeVo);
    }

    @PostMapping("/sendUpdatePwdCode")
    @ApiOperation(value = "发送修改密码验证码")
    public Result<String> sendUpdatePwdCode(@RequestBody @Valid EmailCodeVo emailCodeVo){
        return leaseUserService.sendUpdatePwdCode(emailCodeVo);
    }

    /*-----------------------------谷歌双重验证接口----------------------------*/

    @Decrypt
    @LoginRequired
    @PostMapping("/bindGoogle")
    @ApiOperation(value = "绑定开启谷歌验证")
    public Result<String> bindGoogle(@RequestBody @Valid GoogleBindVo googleBindVo){
        return leaseUserService.bindGoogle(googleBindVo);
    }

    @LoginRequired
    @PostMapping("/getBindInfo")
    @ApiOperation(value = "获取谷歌验证器安全码和验证码")
    public Result<GoogleInfoDto> getBindInfo(){
        return  leaseUserService.getBindInfo();

    }

    @LoginRequired
    @PostMapping("/sendOpenGoogleCode")
    @ApiOperation(value = "开启谷歌验证器 发送邮箱验证码")
    public Result<String> sendOpenGoogleCode(){
        return  leaseUserService.sendOpenGoogleCode();

    }

    @LoginRequired
    @PostMapping("/sendCloseGoogleCode")
    @ApiOperation(value = "关闭谷歌验证器 发送邮箱验证码")
    public  Result<String> sendCloseGoogleCode(){
        return  leaseUserService.sendCloseGoogleCode();

    }

    @LoginRequired
    @PostMapping("/closeStepTwo")
    @ApiOperation(value = "关闭双重验证")
    public  Result<String> closeStepTwo(@Valid @RequestBody GoogleCloseVo vo){
        return  leaseUserService.closeStepTwo(vo);

    }

    /*-----------------------------谷歌双重验证接口----------------------------*/


}

