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.SkuInfoDto;
import com.mall.product.domain.entity.SkuInfo;
import com.mall.product.domain.vo.SkuInfoVo;
import com.mall.product.service.SkuInfoService;
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/skuInfo")
@RequiredArgsConstructor
public class SkuInfoController {

    private final SkuInfoService skuInfoService;

    @Operation(summary = "分页查询sku信息", description = "分页sku信息")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SkuInfoVo>> getSkuInfoPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SkuInfoDto dto) {
        Page<SkuInfo> pageParams = new Page<>(page, limit);
        PageResult<SkuInfoVo> pageResult = skuInfoService.getSkuInfoPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加sku信息", description = "添加sku信息")
    @PostMapping()
    public Result<String> addSkuInfo(@Valid @RequestBody SkuInfoDto dto) {
        skuInfoService.addSkuInfo(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新sku信息", description = "更新sku信息")
    @PutMapping()
    public Result<String> updateSkuInfo(@Valid @RequestBody SkuInfoDto dto) {
        skuInfoService.updateSkuInfo(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除sku信息", description = "删除sku信息")
    @DeleteMapping()
    public Result<String> deleteSkuInfo(@RequestBody List<Long> ids) {
        skuInfoService.deleteSkuInfo(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}