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

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
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.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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/merchant/goods/comment")
public class MerchantGoodsCommentController {

    private final IAdminGoodsCommentService commentService;

    @PostMapping("/page")
    @Operation(summary = "获得商品评价分页")
    @SaCheckPermission("admin:goods:comment:page")
    public ResultBean<PageListBean<GoodsCommentResp>> getOrderPage(@RequestBody GoodsCommentPageReqVO reqVO) {
        reqVO.setMerchantId(StpUtil.getLoginIdAsInt());
        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("/reply")
    @Operation(summary = "回复评价")
    @SaCheckPermission("admin:goods:comment:reply")
    public ResultBean<Boolean> replyComment(@RequestBody GoodsCommentUpdateReq updateReq) {
        return ResultBean.success(commentService.replyComment(updateReq));
    }
}