package com.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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 com.mall.product.domain.dto.SkuSaleAttrValueDto;
import com.mall.product.domain.entity.SkuSaleAttrValue;
import com.mall.product.domain.vo.SkuSaleAttrValueVo;
import com.mall.product.service.SkuSaleAttrValueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * sku销售属性&值 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 15:19:19
 */
@Tag(name = "sku销售属性&值", description = "sku销售属性&值相关接口")
@RestController
@RequestMapping("/api/product/skuSaleAttrValue")
@RequiredArgsConstructor
public class SkuSaleAttrValueController {

    private final SkuSaleAttrValueService skuSaleAttrValueService;

    @Operation(summary = "分页查询sku销售属性&值", description = "分页sku销售属性&值")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SkuSaleAttrValueVo>> getSkuSaleAttrValuePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SkuSaleAttrValueDto dto) {
        Page<SkuSaleAttrValue> pageParams = new Page<>(page, limit);
        PageResult<SkuSaleAttrValueVo> pageResult = skuSaleAttrValueService.getSkuSaleAttrValuePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加sku销售属性&值", description = "添加sku销售属性&值")
    @PostMapping()
    public Result<String> addSkuSaleAttrValue(@Valid @RequestBody SkuSaleAttrValueDto dto) {
        skuSaleAttrValueService.addSkuSaleAttrValue(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新sku销售属性&值", description = "更新sku销售属性&值")
    @PutMapping()
    public Result<String> updateSkuSaleAttrValue(@Valid @RequestBody SkuSaleAttrValueDto dto) {
        skuSaleAttrValueService.updateSkuSaleAttrValue(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除sku销售属性&值", description = "删除sku销售属性&值")
    @DeleteMapping()
    public Result<String> deleteSkuSaleAttrValue(@RequestBody List<Long> ids) {
        skuSaleAttrValueService.deleteSkuSaleAttrValue(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}