package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.SkuLadderDto;
import com.mall.coupon.domain.entity.SkuLadder;
import com.mall.coupon.domain.vo.SkuLadderVo;
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.SkuLadderService;
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-ladder")
@RequiredArgsConstructor
public class SkuLadderController {

    private final SkuLadderService skuLadderService;

    @Operation(summary = "分页查询商品阶梯价格", description = "分页商品阶梯价格")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SkuLadderVo>> getSkuLadderPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SkuLadderDto dto) {
        Page<SkuLadder> pageParams = new Page<>(page, limit);
        PageResult<SkuLadderVo> pageResult = skuLadderService.getSkuLadderPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加商品阶梯价格", description = "添加商品阶梯价格")
    @PostMapping()
    public Result<String> addSkuLadder(@Valid @RequestBody SkuLadderDto dto) {
            skuLadderService.addSkuLadder(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新商品阶梯价格", description = "更新商品阶梯价格")
    @PutMapping()
    public Result<String> updateSkuLadder(@Valid @RequestBody SkuLadderDto dto) {
            skuLadderService.updateSkuLadder(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除商品阶梯价格", description = "删除商品阶梯价格")
    @DeleteMapping()
    public Result<String> deleteSkuLadder(@RequestBody List<Long> ids) {
            skuLadderService.deleteSkuLadder(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}