package com.ruoyi.web.controller.commonapi;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.commonapi.cache.limit.annotation.LimitPoint;
import com.ruoyi.commonapi.enums.ResultUtil;
import com.ruoyi.commonapi.entity.enums.VerificationEnums;
import com.ruoyi.commonapi.service.VerificationService;
import com.ruoyi.commonapi.vo.ResultMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * 滑块验证码接口
 *
 * @author zq
 * @since 2020/11/26 15:41
 */
@Slf4j
@RestController
@RequestMapping("/common/slider")
@Api(tags = "滑块验证码接口")
public class SliderImageController {

    @Resource
    private VerificationService verificationService;

    @LimitPoint(name = "slider_image", key = "verification")
    @GetMapping("/{verificationEnums}")
    @ApiOperation(value = "获取校验接口,一分钟同一个ip请求10次")
    public AjaxResult getSliderImage(@RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
        return AjaxResult.success(verificationService.createVerification(verificationEnums, uuid));

    }

    @LimitPoint(name = "slider_image", key = "verification_pre_check", limit = 600)
    @PostMapping("/{verificationEnums}")
    @ApiOperation(value = "验证码预校验")
    public AjaxResult verificationImage(Integer xPos, @RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
        return AjaxResult.success(verificationService.preCheck(xPos, uuid, verificationEnums));
    }
}
