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.SpuInfoDescDto;
import com.mall.product.domain.entity.SpuInfoDesc;
import com.mall.product.domain.vo.SpuInfoDescVo;
import com.mall.product.service.SpuInfoDescService;
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/spuInfoDesc")
@RequiredArgsConstructor
public class SpuInfoDescController {

    private final SpuInfoDescService spuInfoDescService;

    @Operation(summary = "分页查询spu信息介绍", description = "分页spu信息介绍")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SpuInfoDescVo>> getSpuInfoDescPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SpuInfoDescDto dto) {
        Page<SpuInfoDesc> pageParams = new Page<>(page, limit);
        PageResult<SpuInfoDescVo> pageResult = spuInfoDescService.getSpuInfoDescPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加spu信息介绍", description = "添加spu信息介绍")
    @PostMapping()
    public Result<String> addSpuInfoDesc(@Valid @RequestBody SpuInfoDescDto dto) {
        spuInfoDescService.addSpuInfoDesc(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新spu信息介绍", description = "更新spu信息介绍")
    @PutMapping()
    public Result<String> updateSpuInfoDesc(@Valid @RequestBody SpuInfoDescDto dto) {
        spuInfoDescService.updateSpuInfoDesc(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除spu信息介绍", description = "删除spu信息介绍")
    @DeleteMapping()
    public Result<String> deleteSpuInfoDesc(@RequestBody List<Long> ids) {
        spuInfoDescService.deleteSpuInfoDesc(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}