package com.sv.api.controller;

import com.sv.service.common.SmsService;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 发生验证码
 */
@RestController
public class SmsController extends BaseApiController {

    private final Logger logger = LoggerFactory.getLogger(SmsController.class);

    @Resource
    private SmsService smsService;

    /**
     * 发送注册验证码
     * type 1绑定手机，2手机号码注册
     */
    @RequestMapping(value = "/member/sms/register" , method = RequestMethod.POST)
    public ResponseDTO sendRegisterCaptcha(@Param("mobile") String mobile,@Param("type")Integer type) {
        smsService.sendRegisterCaptcha(mobile,type);
        return ResponseDTO.ok();
    }

    /**
     * 发送登录验证码
     */
    @RequestMapping(value = "/member/sms/login" , method = RequestMethod.POST)
    public ResponseDTO sendLoginCaptcha(@Param("mobile") String mobile) {
        smsService.sendLoginCaptcha(mobile);
        return ResponseDTO.ok();
    }

    /**
     * 发送修改手机号码验证码
     */
    @RequestMapping(value = "/member/sms/update" , method = RequestMethod.POST)
    public ResponseDTO sendUpdatePhoneCaptcha(@Param("mobile") String mobile) {
        smsService.sendUpdatePhoneCaptcha(mobile);
        return ResponseDTO.ok();
    }
}
