package com.seer.teach.mall.good.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.mall.good.service.IAdminGoodsCommentService;
import com.seer.teach.mall.request.CommentUpdateVisibleReq;
import com.seer.teach.mall.request.GoodsCommentCreateReq;
import com.seer.teach.mall.request.GoodsCommentPageReqVO;
import com.seer.teach.mall.request.GoodsCommentUpdateReq;
import com.seer.teach.mall.response.GoodsCommentResp;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商品评论 前端控制器
 * </p>
 *
 * @author Wang
 * @since 2025-07-03 10:22:05
 */
@Tag(name = "管理端 - 商品评价管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/goods/comment")
public class AdminGoodsCommentController {

    private final IAdminGoodsCommentService commentService;

    @PostMapping("/page")
    @Operation(summary = "获得商品评价分页")
    @SaCheckPermission("admin:goods:comment:page")
    public ResultBean<PageListBean<GoodsCommentResp>> getOrderPage(@RequestBody GoodsCommentPageReqVO reqVO) {
        return ResultBean.success(commentService.getOrderPage(reqVO));
    }

    @PostMapping("/create")
    @Operation(summary = "添加自评")
    @SaCheckPermission("admin:goods:comment:create")
    public ResultBean<Boolean> create(@RequestBody GoodsCommentCreateReq reqVO) {
        return ResultBean.success(commentService.create(reqVO));
    }

    @PutMapping("/update-visible")
    @Operation(summary = "显示 / 隐藏评论")
    @SaCheckPermission("admin:goods:comment:update-visible")
    public ResultBean<Boolean> updateCommentVisible(@Valid @RequestBody CommentUpdateVisibleReq commentUpdateVisibleReq) {
        return ResultBean.success(commentService.updateCommentVisible(commentUpdateVisibleReq));
    }

    @DeleteMapping("/{commentId}/delete")
    @Operation(summary = "删除评论")
    @SaCheckPermission("admin:goods:comment:delete")
    public ResultBean<Boolean> delete(@PathVariable("commentId") Integer commentId) {
        return ResultBean.success(commentService.removeById(commentId));
    }

    @DeleteMapping("/batchDelete")
    @Operation(summary = "批量删除评论")
    @SaCheckPermission("admin:goods:comment:batchDelete")
    public ResultBean<Boolean> batchDelete(@RequestBody List<Integer> commentIds) {
        return ResultBean.success(commentService.removeBatchByIds(commentIds));
    }


    @PutMapping("/reply")
    @Operation(summary = "回复评价")
    @SaCheckPermission("admin:goods:comment:reply")
    public ResultBean<Boolean> replyComment(@RequestBody GoodsCommentUpdateReq updateReq) {
        return ResultBean.success(commentService.replyComment(updateReq));
    }
}