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.SpuImagesDto;
import com.mall.product.domain.entity.SpuImages;
import com.mall.product.domain.vo.SpuImagesVo;
import com.mall.product.service.SpuImagesService;
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/spuImages")
@RequiredArgsConstructor
public class SpuImagesController {

    private final SpuImagesService spuImagesService;

    @Operation(summary = "分页查询spu图片", description = "分页spu图片")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SpuImagesVo>> getSpuImagesPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SpuImagesDto dto) {
        Page<SpuImages> pageParams = new Page<>(page, limit);
        PageResult<SpuImagesVo> pageResult = spuImagesService.getSpuImagesPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加spu图片", description = "添加spu图片")
    @PostMapping()
    public Result<String> addSpuImages(@Valid @RequestBody SpuImagesDto dto) {
        spuImagesService.addSpuImages(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新spu图片", description = "更新spu图片")
    @PutMapping()
    public Result<String> updateSpuImages(@Valid @RequestBody SpuImagesDto dto) {
        spuImagesService.updateSpuImages(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

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