package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SpuBoundsDto;
import com.mall.coupon.domain.entity.SpuBounds;
import com.mall.coupon.domain.vo.SpuBoundsVo;
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.SpuBoundsService;
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>
 * 商品spu积分设置 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-06 11:15:40
 */
@Tag(name = "商品spu积分设置", description = "商品spu积分设置相关接口")
@RestController
@RequestMapping("/api/coupon/spu-bounds")
@RequiredArgsConstructor
public class SpuBoundsController {

    private final SpuBoundsService spuBoundsService;

    @Operation(summary = "分页查询商品spu积分设置", description = "分页商品spu积分设置")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SpuBoundsVo>> getSpuBoundsPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SpuBoundsDto dto) {
        Page<SpuBounds> pageParams = new Page<>(page, limit);
        PageResult<SpuBoundsVo> pageResult = spuBoundsService.getSpuBoundsPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加商品spu积分设置", description = "添加商品spu积分设置")
    @PostMapping()
    public Result<String> addSpuBounds(@Valid @RequestBody SpuBoundsDto dto) {
            spuBoundsService.addSpuBounds(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新商品spu积分设置", description = "更新商品spu积分设置")
    @PutMapping()
    public Result<String> updateSpuBounds(@Valid @RequestBody SpuBoundsDto dto) {
            spuBoundsService.updateSpuBounds(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除商品spu积分设置", description = "删除商品spu积分设置")
    @DeleteMapping()
    public Result<String> deleteSpuBounds(@RequestBody List<Long> ids) {
            spuBoundsService.deleteSpuBounds(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}