package com.webchat.controller.admin;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.helper.SessionHelper;
import com.webchat.config.annotation.ValidatePermission;
import com.webchat.domain.vo.request.lottery.LotteryItemSaveVO;
import com.webchat.domain.vo.response.lottery.LotteryItemVO;
import com.webchat.service.lottery.LotteryItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    @Autowired
    private LotteryItemService lotteryItemService;

    /**
     * 新建或更新奖品信息
     * @return
     */
    @ApiOperation("新建或更新奖品信息")
    @ValidatePermission
    @PostMapping("/save")
    public APIResponseBean<Long> save(@RequestBody LotteryItemSaveVO lotteryItemSaveVO) {
        String userId = SessionHelper.getCurrentUserId();
        return APIResponseBeanUtil.success(lotteryItemService.save(lotteryItemSaveVO, userId));
    }

    /**
     * 奖品列表查询
     * @param name
     * @param slot
     * @param activityId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation("奖品列表查询")
    @ValidatePermission
    @GetMapping("/page")
    public APIPageResponseBean<List<LotteryItemVO>> pageList(@RequestParam(value = "activityId", required = false) String activityId,
                                                             @RequestParam(value = "name", required = false) String name,
                                                             @RequestParam(value = "slot", required = false) Integer slot,
                                                             @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return lotteryItemService.pageList(activityId, name, slot, pageNo, pageSize);
    }
}
