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.bo.MallPromotionBo;
import org.dromara.mall.promotion.domain.vo.MallPromotionVo;
import org.dromara.mall.promotion.service.MallPromotionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    private final MallPromotionService mallPromotionService;

    /**
     * 查询营销活动列表（按类型）
     */
    @Operation(summary = "查询营销活动列表", description = "根据活动类型查询启用的营销活动列表")
    @GetMapping("/list")
    public R<List<MallPromotionVo>> list(@Parameter(description = "活动类型(0普通活动 1拼团 2秒杀 3砍价)")
                                         @RequestParam(required = false) Integer type) {
        List<MallPromotionVo> list;
        if (type != null) {
            list = mallPromotionService.queryListByType(type);
        } else {
            list = mallPromotionService.queryList(new MallPromotionBo());
        }
        return R.ok(list);
    }

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

}
