package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SeckillSkuRelationDto;
import com.mall.coupon.domain.entity.SeckillSkuRelation;
import com.mall.coupon.domain.vo.SeckillSkuRelationVo;
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.SeckillSkuRelationService;
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-relation")
@RequiredArgsConstructor
public class SeckillSkuRelationController {

    private final SeckillSkuRelationService seckillSkuRelationService;

    @Operation(summary = "分页查询秒杀活动商品关联", description = "分页秒杀活动商品关联")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SeckillSkuRelationVo>> getSeckillSkuRelationPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SeckillSkuRelationDto dto) {
        Page<SeckillSkuRelation> pageParams = new Page<>(page, limit);
        PageResult<SeckillSkuRelationVo> pageResult = seckillSkuRelationService.getSeckillSkuRelationPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加秒杀活动商品关联", description = "添加秒杀活动商品关联")
    @PostMapping()
    public Result<String> addSeckillSkuRelation(@Valid @RequestBody SeckillSkuRelationDto dto) {
            seckillSkuRelationService.addSeckillSkuRelation(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新秒杀活动商品关联", description = "更新秒杀活动商品关联")
    @PutMapping()
    public Result<String> updateSeckillSkuRelation(@Valid @RequestBody SeckillSkuRelationDto dto) {
            seckillSkuRelationService.updateSeckillSkuRelation(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

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