package ink.wgink.module.sms.controller.resources.sms;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.sms.pojo.vos.sms.SmsPhoneSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import io.swagger.annotations.*;
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;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: VerificationCodeController
 * @Description: 验证码
 * @Author: WangGeng
 * @Date: 2020/3/4 7:13 下午
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "短信")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/sms")
public class SmsResourceController extends DefaultBaseController {

    @Autowired
    private ISmsService smsService;

    @ApiOperation(value = "发送短信", notes = "发送短信接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("send")
    @CheckRequestBodyAnnotation
    public SuccessResult send(@RequestBody SmsSendVO smsSendVO) throws Exception {
        smsService.send(smsSendVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "手机用户名发送短信", notes = "通过手机号发送短信接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("send/phones")
    @CheckRequestBodyAnnotation
    public SuccessResult sendByPhones(@RequestBody SmsPhoneSendVO smsPhoneSendVO) throws Exception {
        smsService.sendByPhones(smsPhoneSendVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "手机号直接发送短信", notes = "通过手机号直接发送短信短信接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("send-directly/phones")
    @CheckRequestBodyAnnotation
    public SuccessResult sendDirectlyByPhones(@RequestBody SmsPhoneSendVO smsPhoneSendVO) throws Exception {
        smsService.sendDirectlyByPhones(smsPhoneSendVO);
        return new SuccessResult();
    }

}
