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.SkuImagesDto;
import com.mall.product.domain.entity.SkuImages;
import com.mall.product.domain.vo.SkuImagesVo;
import com.mall.product.service.SkuImagesService;
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/skuImages")
@RequiredArgsConstructor
public class SkuImagesController {

    private final SkuImagesService skuImagesService;

    @Operation(summary = "分页查询sku图片", description = "分页sku图片")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SkuImagesVo>> getSkuImagesPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SkuImagesDto dto) {
        Page<SkuImages> pageParams = new Page<>(page, limit);
        PageResult<SkuImagesVo> pageResult = skuImagesService.getSkuImagesPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加sku图片", description = "添加sku图片")
    @PostMapping()
    public Result<String> addSkuImages(@Valid @RequestBody SkuImagesDto dto) {
        skuImagesService.addSkuImages(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新sku图片", description = "更新sku图片")
    @PutMapping()
    public Result<String> updateSkuImages(@Valid @RequestBody SkuImagesDto dto) {
        skuImagesService.updateSkuImages(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除sku图片", description = "删除sku图片")
    @DeleteMapping()
    public Result<String> deleteSkuImages(@RequestBody List<Long> ids) {
        skuImagesService.deleteSkuImages(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}