package com.webchat.controller;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.config.annotation.ValidatePermission;
import com.webchat.domain.vo.request.SlideVerificationVO;
import com.webchat.service.SlideVerificationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 程序员七七
 * @webSite https://www.coderutil.com
 * @Date 2024/9/18 23:46
 * @description
 */
@Api(tags = "滑块验证码")
@RestController
@RequestMapping("/api/slide/verification")
public class SlideVerificationController {

    @Autowired
    private SlideVerificationService slideVerificationService;


    @ValidatePermission
    @PostMapping("/save")
    public APIResponseBean<Long> save(@RequestBody SlideVerificationVO slideVerificationVO) {
        Long id = slideVerificationService.save(slideVerificationVO);
        return APIResponseBeanUtil.success(id);
    }

    @ValidatePermission
    @PostMapping("/status/{id}/{status}")
    public APIResponseBean<Long> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        slideVerificationService.updateStatus(id, status);
        return APIResponseBeanUtil.success();
    }

    @GetMapping("/get")
    public APIResponseBean<SlideVerificationVO> get() {
        SlideVerificationVO slideVerification = slideVerificationService.get();
        return APIResponseBeanUtil.success(slideVerification);
    }

    @PostMapping("/valid/{accessToken}")
    public APIResponseBean<Boolean> validate(@PathVariable String accessToken) {
        boolean validateResult = slideVerificationService.validate(accessToken);
        return APIResponseBeanUtil.success(validateResult);
    }

    @ValidatePermission
    @GetMapping("/page")
    public APIPageResponseBean<SlideVerificationVO> page(@RequestParam(value = "status", required = false) Integer status,
                                                         @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return slideVerificationService.pageList(status, pageNo, pageSize);
    }
}
