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.ProductAttrValueDto;
import com.mall.product.domain.entity.ProductAttrValue;
import com.mall.product.domain.vo.ProductAttrValueVo;
import com.mall.product.service.ProductAttrValueService;
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>
 * spu属性值 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 15:19:19
 */
@Tag(name = "spu属性值", description = "spu属性值相关接口")
@RestController
@RequestMapping("/api/product/productAttrValue")
@RequiredArgsConstructor
public class ProductAttrValueController {

    private final ProductAttrValueService productAttrValueService;

    @Operation(summary = "分页查询spu属性值", description = "分页spu属性值")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<ProductAttrValueVo>> getProductAttrValuePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            ProductAttrValueDto dto) {
        Page<ProductAttrValue> pageParams = new Page<>(page, limit);
        PageResult<ProductAttrValueVo> pageResult = productAttrValueService.getProductAttrValuePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加spu属性值", description = "添加spu属性值")
    @PostMapping()
    public Result<String> addProductAttrValue(@Valid @RequestBody ProductAttrValueDto dto) {
        productAttrValueService.addProductAttrValue(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新spu属性值", description = "更新spu属性值")
    @PutMapping()
    public Result<String> updateProductAttrValue(@Valid @RequestBody ProductAttrValueDto dto) {
        productAttrValueService.updateProductAttrValue(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除spu属性值", description = "删除spu属性值")
    @DeleteMapping()
    public Result<String> deleteProductAttrValue(@RequestBody List<Long> ids) {
        productAttrValueService.deleteProductAttrValue(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}