package com.diagbot.web;

import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.ImgVerCreatDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.facade.VerFacade;
import com.diagbot.vo.ImgVerVerVO;
import com.diagbot.vo.SmsVerCreatVO;
import com.diagbot.vo.SmsVerVerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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.validation.Valid;

/**
 * @Description: 用户验证API
 * @author: gaodm
 * @time: 2018/9/4 19:30
 */
@RestController
@Api(value="用户验证API", tags={"用户手机图片验证API"})
@RequestMapping("/userver")
@SuppressWarnings("unchecked")
public class VerController {
    @Autowired
    private VerFacade verFacade;

    /**
     * 获取图片验证码
     * @return 图片验证码包括图片验证码唯一标志和图片信息
     */
    @ApiOperation(value = "获取图片验证码[by:zhoutg]", notes = "获取图片验证码包括图片验证码唯一标志和图片信息")
    @PostMapping("/getImgVerification")
    @SysLogger("getImgVerification")
    public RespDTO<ImgVerCreatDTO> getImgVerification(){
        return   RespDTO.onSuc(verFacade.getImgVerification());
    }

    /**
     * 验证图片验证码信息
     * @param imgVerVerVO 验证图片验证码所需参数
     * @return 是否验证成功
     */
    @ApiOperation(value = "验证图片验证码[by:zhoutg]",
            notes = "imgId：图片id<br>" +
                    "code：图片验证码<br>")
    @PostMapping("/verifyImgVerification")
    @SysLogger("verifyImgVerification")
    public RespDTO<Boolean> verImgVerification(@RequestBody @Valid ImgVerVerVO imgVerVerVO){
        return  RespDTO.onSuc(verFacade.verifyImgVerification(imgVerVerVO));
    }

    /**
     * 注册获取短信验证码
     * @param smsVerCreatVO 获取短信验证码输入参数
     * @return 获取短信验证码是否成功
     */
    @ApiOperation(value = "注册获取短信验证码[by:zhoutg]",
            notes = "mobile：手机号，必填<br>" +
                    "imgId：图片id<br>" +
                    "code：图片验证码<br>")
    @PostMapping("/getSmsWithRegister")
    @SysLogger("getSmsWithRegister")
    public RespDTO<Boolean> getSmsWithRegister(@RequestBody @Valid SmsVerCreatVO smsVerCreatVO){
        return   RespDTO.onSuc(verFacade.getSmsVerification(smsVerCreatVO));
    }


    /**
     * 验证注册短信码并且注册为新的用户
     * @param smsVerVerVO 短信验证码验证输入信息
     * @return 用户信息是否注册到数据库
     */
    @ApiOperation(value = "验证短信验证码[by:zhoutg]",
            notes = "mobile：手机号，必填<br>" +
                    "smsCode：短信验证码，必填<br>")
    @PostMapping("/verifySmsVerification")
    @SysLogger("verifySmsVerification")
    public RespDTO<Boolean> verifySmsVerification(@RequestBody SmsVerVerVO smsVerVerVO){
        return RespDTO.onSuc(verFacade.verifySmsVerification(smsVerVerVO));
    }


    /**
     * 忘记密码获取短信验证码
     * @param smsVerCreatVO 获取短信验证码输入参数
     * @return 获取短信验证码是否成功
     */
    @ApiOperation(value = "忘记密码获取短信验证码[by:zhoutg]",
            notes = "mobile：手机号，必填<br>" +
                    "imgId：图片id<br>" +
                    "code：图片验证码<br>")
    @PostMapping("/getSmsWithResetPassword")
    @SysLogger("getSmsWithResetPassword")
    public RespDTO<Boolean> getSmsWithResetPassword(@RequestBody @Valid SmsVerCreatVO smsVerCreatVO){
        return   RespDTO.onSuc(verFacade.getSmsWithResetPassword(smsVerCreatVO));
    }

}
