package org.jeecg.modules.shop.captcha.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.shop.captcha.entity.SendSmsCaptchaDTO;
import org.jeecg.modules.shop.captcha.entity.VerifySmsCaptchaDTO;
import org.jeecg.modules.shop.captcha.service.ICaptchaService;
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;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Api(tags = "合作伙伴-验证码服务")
@RestController
@RequestMapping("/captcha")
@RequiredArgsConstructor
public class CaptchaController {
    
    private final ICaptchaService service;
    
    @IgnoreAuth
    @PostMapping("/sms/send")
    @ApiOperation(value = "发送短信验证码  type = partner_login", notes = "发送短信验证码 type = partner_login")
    public Result<?> sendSmsCaptcha(@RequestBody @Valid SendSmsCaptchaDTO dto) {
        service.sendSmsCaptcha(dto);
        return Result.OK();
    }

    @IgnoreAuth
    @PostMapping("/sms/verify")
    @ApiOperation(value = "验证短信验证码（", notes = "验证短信验证码，验证成功后验证码立即失效")
    public Result<Map<String, String>> verifySmsCaptcha(@RequestBody @Valid VerifySmsCaptchaDTO dto) {
        String key = service.verifySmsCaptcha(dto);
        Map<String, String> map = new HashMap<>();
        map.put("token", key);
        return Result.OK(map);
    }
    
}
