package org.dromara.mall.promotion.controller.app;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.promotion.domain.vo.MallSeckillVo;
import org.dromara.mall.promotion.service.MallSeckillService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 秒杀活动（移动端）
 *
 * @author pengles
 */
@Tag(name = "移动端-秒杀活动", description = "秒杀活动接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/mall/seckill")
public class AppMallSeckillController extends BaseController {

    private final MallSeckillService mallSeckillService;

    /**
     * 查询可用秒杀活动列表
     */
    @Operation(summary = "查询可用秒杀活动列表", description = "查询当前可用的秒杀活动列表")
    @GetMapping("/list")
    public R<List<MallSeckillVo>> list() {
        List<MallSeckillVo> list = mallSeckillService.queryAvailableList();
        return R.ok(list);
    }

    /**
     * 获取秒杀活动详情
     */
    @Operation(summary = "获取秒杀活动详情", description = "根据秒杀活动ID获取详细信息")
    @GetMapping("/{id}")
    public R<MallSeckillVo> getInfo(@Parameter(description = "秒杀活动ID", required = true)
                                    @PathVariable Long id) {
        return R.ok(mallSeckillService.queryById(id));
    }

    /**
     * 根据SKU ID查询秒杀活动
     */
    @Operation(summary = "根据SKU ID查询秒杀活动", description = "查询指定SKU的秒杀活动")
    @GetMapping("/sku/{skuId}")
    public R<MallSeckillVo> getBySkuId(@Parameter(description = "SKU ID", required = true)
                                       @PathVariable Long skuId) {
        MallSeckillVo vo = mallSeckillService.queryBySkuId(skuId);
        return R.ok(vo);
    }

}
