package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SeckillSkuNoticeDto;
import com.mall.coupon.domain.entity.SeckillSkuNotice;
import com.mall.coupon.domain.vo.SeckillSkuNoticeVo;
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.SeckillSkuNoticeService;
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-sku-notice")
@RequiredArgsConstructor
public class SeckillSkuNoticeController {

    private final SeckillSkuNoticeService seckillSkuNoticeService;

    @Operation(summary = "分页查询秒杀商品通知订阅", description = "分页秒杀商品通知订阅")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SeckillSkuNoticeVo>> getSeckillSkuNoticePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SeckillSkuNoticeDto dto) {
        Page<SeckillSkuNotice> pageParams = new Page<>(page, limit);
        PageResult<SeckillSkuNoticeVo> pageResult = seckillSkuNoticeService.getSeckillSkuNoticePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加秒杀商品通知订阅", description = "添加秒杀商品通知订阅")
    @PostMapping()
    public Result<String> addSeckillSkuNotice(@Valid @RequestBody SeckillSkuNoticeDto dto) {
            seckillSkuNoticeService.addSeckillSkuNotice(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新秒杀商品通知订阅", description = "更新秒杀商品通知订阅")
    @PutMapping()
    public Result<String> updateSeckillSkuNotice(@Valid @RequestBody SeckillSkuNoticeDto dto) {
            seckillSkuNoticeService.updateSeckillSkuNotice(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除秒杀商品通知订阅", description = "删除秒杀商品通知订阅")
    @DeleteMapping()
    public Result<String> deleteSeckillSkuNotice(@RequestBody List<Long> ids) {
            seckillSkuNoticeService.deleteSeckillSkuNotice(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}