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.CommentReplayDto;
import com.mall.product.domain.entity.CommentReplay;
import com.mall.product.domain.vo.CommentReplayVo;
import com.mall.product.service.CommentReplayService;
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/commentReplay")
@RequiredArgsConstructor
public class CommentReplayController {

    private final CommentReplayService commentReplayService;

    @Operation(summary = "分页查询商品评价回复关系", description = "分页商品评价回复关系")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<CommentReplayVo>> getCommentReplayPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            CommentReplayDto dto) {
        Page<CommentReplay> pageParams = new Page<>(page, limit);
        PageResult<CommentReplayVo> pageResult = commentReplayService.getCommentReplayPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加商品评价回复关系", description = "添加商品评价回复关系")
    @PostMapping()
    public Result<String> addCommentReplay(@Valid @RequestBody CommentReplayDto dto) {
        commentReplayService.addCommentReplay(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新商品评价回复关系", description = "更新商品评价回复关系")
    @PutMapping()
    public Result<String> updateCommentReplay(@Valid @RequestBody CommentReplayDto dto) {
        commentReplayService.updateCommentReplay(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

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