package ink.wgink.module.sms.controller.app.api.sms;

import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.util.RegexUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: SmsAppController
 * @Description: 短信
 * @Author: wanggeng
 * @Date: 2021/5/1 3:05 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "验证码接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/sms")
public class SmsAppController {

    @Autowired
    private ISmsService smsService;

    @ApiOperation(value = "获取短信验证码", notes = "获取短信验证码接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("verify-code/{phone}")
    public SuccessResult verifyCode(@PathVariable("phone") String phone) {
        if (!RegexUtil.isPhone(phone)) {
            throw new ParamsException("手机号格式错误");
        }
        smsService.sendVerifyCode(phone);
        return new SuccessResult();
    }

}
