package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SeckillPromotionDto;
import com.mall.coupon.domain.entity.SeckillPromotion;
import com.mall.coupon.domain.vo.SeckillPromotionVo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import com.mall.coupon.service.SeckillPromotionService;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 秒杀活动 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-06 11:15:40
 */
@Tag(name = "秒杀活动", description = "秒杀活动相关接口")
@RestController
@RequestMapping("/api/coupon/seckill-promotion")
@RequiredArgsConstructor
public class SeckillPromotionController {

    private final SeckillPromotionService seckillPromotionService;

    @Operation(summary = "分页查询秒杀活动", description = "分页秒杀活动")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SeckillPromotionVo>> getSeckillPromotionPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SeckillPromotionDto dto) {
        Page<SeckillPromotion> pageParams = new Page<>(page, limit);
        PageResult<SeckillPromotionVo> pageResult = seckillPromotionService.getSeckillPromotionPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加秒杀活动", description = "添加秒杀活动")
    @PostMapping()
    public Result<String> addSeckillPromotion(@Valid @RequestBody SeckillPromotionDto dto) {
            seckillPromotionService.addSeckillPromotion(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新秒杀活动", description = "更新秒杀活动")
    @PutMapping()
    public Result<String> updateSeckillPromotion(@Valid @RequestBody SeckillPromotionDto dto) {
            seckillPromotionService.updateSeckillPromotion(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除秒杀活动", description = "删除秒杀活动")
    @DeleteMapping()
    public Result<String> deleteSeckillPromotion(@RequestBody List<Long> ids) {
            seckillPromotionService.deleteSeckillPromotion(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}