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.MallGroupBuyVo;
import org.dromara.mall.promotion.service.MallGroupBuyService;
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/groupbuy")
public class AppMallGroupBuyController extends BaseController {

    private final MallGroupBuyService mallGroupBuyService;

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

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

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

}
