package com.webchat.controller.admin;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.enums.ClickEvent;
import com.webchat.common.helper.SessionHelper;
import com.webchat.config.annotation.SafeClick;
import com.webchat.config.annotation.ValidateLogin;
import com.webchat.domain.vo.response.lottery.LotteryDrawBulkResponseVO;
import com.webchat.service.lottery.LotteryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 程序员七七
 * @webSite https://www.coderutil.com
 * @Date 2022/11/16 23:40
 * @description
 */
@Api(tags = "【幸运抽奖】抽奖服务")
@RestController
@RequestMapping("/api/lottery")
public class LotteryController {

    @Autowired
    private LotteryService lotteryService;

    /**
     * 抽奖
     * @return
     */
    @ApiOperation("单次抽奖")
    @ValidateLogin
    @SafeClick(event = ClickEvent.LUCK_LOTTERY, time = 5000L, message = "异常操作多次后账号将会永久拉黑")
    @PostMapping("/luckDraw/{lotteryActivityId}")
    public APIResponseBean<Long> luckDraw(@PathVariable String lotteryActivityId) {
        String userId = SessionHelper.getCurrentUserId();
        return APIResponseBeanUtil.success(lotteryService.luckDraw(lotteryActivityId, userId));
    }

    /**
     * 抽奖
     * @return
     */
    @ApiOperation("十连抽奖")
    @ValidateLogin
    @SafeClick(event = ClickEvent.SUBMIT, time = 5000L, message = "异常操作多次后账号将会永久拉黑")
    @PostMapping("/luckDraw/{lotteryActivityId}/10")
    public APIResponseBean<LotteryDrawBulkResponseVO> luckDraw10Times(@PathVariable String lotteryActivityId) {
        String userId = SessionHelper.getCurrentUserId();
        LotteryDrawBulkResponseVO batchLuckDrawResult = lotteryService.luckDraw(lotteryActivityId, userId, 10);
        return APIResponseBeanUtil.success(batchLuckDrawResult);
    }

}
