package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SeckillSessionDto;
import com.mall.coupon.domain.entity.SeckillSession;
import com.mall.coupon.domain.vo.SeckillSessionVo;
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.SeckillSessionService;
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-session")
@RequiredArgsConstructor
public class SeckillSessionController {

    private final SeckillSessionService seckillSessionService;

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

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

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

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