package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SkuFullReductionDto;
import com.mall.coupon.domain.entity.SkuFullReduction;
import com.mall.coupon.domain.vo.SkuFullReductionVo;
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.SkuFullReductionService;
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/sku-full-reduction")
@RequiredArgsConstructor
public class SkuFullReductionController {

    private final SkuFullReductionService skuFullReductionService;

    @Operation(summary = "分页查询商品满减信息", description = "分页商品满减信息")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SkuFullReductionVo>> getSkuFullReductionPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SkuFullReductionDto dto) {
        Page<SkuFullReduction> pageParams = new Page<>(page, limit);
        PageResult<SkuFullReductionVo> pageResult = skuFullReductionService.getSkuFullReductionPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加商品满减信息", description = "添加商品满减信息")
    @PostMapping()
    public Result<String> addSkuFullReduction(@Valid @RequestBody SkuFullReductionDto dto) {
            skuFullReductionService.addSkuFullReduction(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新商品满减信息", description = "更新商品满减信息")
    @PutMapping()
    public Result<String> updateSkuFullReduction(@Valid @RequestBody SkuFullReductionDto dto) {
            skuFullReductionService.updateSkuFullReduction(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除商品满减信息", description = "删除商品满减信息")
    @DeleteMapping()
    public Result<String> deleteSkuFullReduction(@RequestBody List<Long> ids) {
            skuFullReductionService.deleteSkuFullReduction(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}