package com.inkasso.factoring.common.web;

import com.inkasso.factoring.common.entity.ResponseJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.inkasso.factoring.common.service.CommonService;

/**
 * @author liutao
 * @date 2023-11-27
 * 公共接口服务类
 */
@RestController
@RequestMapping("common")
public class CommonController {

    @Autowired
    private CommonService commonService;

    /**
     * 短信生成短信验证码
     * @param phoneNumber
     * @return
     * @throws Exception
     */
    @RequestMapping("sms/verification")
    public ResponseJson SMSVerification(@RequestParam("phoneNumber") String phoneNumber,@RequestParam("type") String type) throws Exception {
        commonService.SMSVerification(phoneNumber,type);
        return new ResponseJson();
    }

    /**
     * 校验短信验证码
     * @param phoneNumber
     * @param code
     * @return
     * @throws Exception
     */
    @RequestMapping("sms/codeTest")
    public ResponseJson SMSCodeTest(@RequestParam String phoneNumber,@RequestParam String code) {
        boolean success = commonService.verifySMSCode(phoneNumber, code);
        return new ResponseJson(success);
    }

    /**
     * 邮件生成短信验证码
     * @param mail
     * @return
     * @throws Exception
     */
    @RequestMapping("mail/verification")
    public ResponseJson mailVerification(@RequestParam String mail,@RequestParam String type) {
        commonService.mailVerification(mail,type);
        return new ResponseJson();
    }

    /**
     * 校验邮件验证码
     * @param mail
     * @param code
     * @return
     * @throws Exception
     */
    @RequestMapping("mail/codeTest")
    public ResponseJson mailCodeTest(@RequestParam String mail,@RequestParam String code) {
        boolean success = commonService.verifyMailCode(mail, code);
        return new ResponseJson(success);
    }
}
