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.SpuCommentDto;
import com.mall.product.domain.entity.SpuComment;
import com.mall.product.domain.vo.SpuCommentVo;
import com.mall.product.service.SpuCommentService;
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>
 * 商品评价 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 15:19:19
 */
@Tag(name = "商品评价", description = "商品评价相关接口")
@RestController
@RequestMapping("/api/product/spuComment")
@RequiredArgsConstructor
public class SpuCommentController {

    private final SpuCommentService spuCommentService;

    @Operation(summary = "分页查询商品评价", description = "分页商品评价")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<SpuCommentVo>> getSpuCommentPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            SpuCommentDto dto) {
        Page<SpuComment> pageParams = new Page<>(page, limit);
        PageResult<SpuCommentVo> pageResult = spuCommentService.getSpuCommentPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加商品评价", description = "添加商品评价")
    @PostMapping()
    public Result<String> addSpuComment(@Valid @RequestBody SpuCommentDto dto) {
        spuCommentService.addSpuComment(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新商品评价", description = "更新商品评价")
    @PutMapping()
    public Result<String> updateSpuComment(@Valid @RequestBody SpuCommentDto dto) {
        spuCommentService.updateSpuComment(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除商品评价", description = "删除商品评价")
    @DeleteMapping()
    public Result<String> deleteSpuComment(@RequestBody List<Long> ids) {
        spuCommentService.deleteSpuComment(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}