package org.springblade.modules.api.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.common.constant.CommonConstant;
import org.springblade.common.enums.YesOrNoEnum;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.mall.entity.SeckillRound;
import org.springblade.modules.mall.service.ISeckillGoodsService;
import org.springblade.modules.mall.service.ISeckillRoundService;
import org.springblade.modules.mall.vo.SeckillGoodsVO;
import org.springblade.modules.mall.vo.SeckillRoundVO;
import org.springblade.modules.mall.wrapper.SeckillRoundWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author pangqijun
 * Date 2023/5/4
 * Description
 */
@RestController
@RequestMapping(CommonConstant.API_URL + "/seckill")
@Api(value = "秒杀相关接口", tags = "12.秒杀相关接口")
public class SeckillController extends BladeController {

    @Resource
    private ISeckillRoundService seckillRoundService;
    @Resource
    private ISeckillGoodsService seckillGoodsService;

    @GetMapping("round")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取秒杀场次")
    public R<List<SeckillRoundVO>> round() {
        List<SeckillRound> list = seckillRoundService.lambdaQuery().eq(SeckillRound::getEnable, YesOrNoEnum.YES.getValue())
                .eq(SeckillRound::getIsDelete, YesOrNoEnum.NO.getValue())
                .orderByAsc(SeckillRound::getStartTime).list();
        return data(SeckillRoundWrapper.build().listVO(list));
    }


    @GetMapping("goods")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取秒杀商品")
    public R<List<SeckillGoodsVO>> goods(@ApiParam(value = "秒杀场次ID")
                                             @RequestParam(value = "seckkillRoundId") Long seckkillRoundId, Query query) {
        return data(seckillGoodsService.getGoods(Condition.getPage(query), seckkillRoundId));
    }
}
