package com.huyi.service.common;

import com.huyi.service.util.ValidateCodeService;
import com.huyi.service.util.impl.MessageUtilsServiceImpl;
import com.tianhu.common.core.web.domain.AjaxResult;
import com.tianhu.common.log.annotation.Log;
import com.tianhu.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/shortMessage")
public class ShortMessageController {
    @Autowired
    MessageUtilsServiceImpl messageUtilsService;
    @Autowired
    private ValidateCodeService validateCodeService;


    @Log(title = "发送短信", businessType = BusinessType.INSERT)
    @Transactional(rollbackFor=Exception.class)
    @PostMapping("/sendShortMessage")
    public AjaxResult sendShortMessage(@RequestBody Map<String, String> requestBody,
                                       HttpServletRequest request) {
        validateCodeService.checkCapcha(requestBody.get("imgCode"), requestBody.get("uuid"));
        messageUtilsService.sendMessageCode(requestBody.get("phone"), requestBody.get("verificationCode"), request);
        return AjaxResult.success();
    }
}
