package shop.alien.lawyer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartRequest;
import shop.alien.entity.result.R;
import shop.alien.entity.store.StoreComment;
import shop.alien.entity.store.dto.OrderReviewDto;
import shop.alien.entity.store.dto.ReviewCommentRequestDto;
import shop.alien.entity.store.dto.ReviewReplyDto;
import shop.alien.entity.store.vo.LifeUserOrderCommentVo;
import shop.alien.entity.store.vo.OrderReviewDetailVo;
import shop.alien.entity.store.vo.OrderReviewVo;
import shop.alien.entity.store.vo.ReviewCommentVo;
import shop.alien.entity.store.vo.StoreCommentCountVo;
import shop.alien.entity.store.vo.StoreCommentVo;
import shop.alien.entity.store.vo.StoreCommitPercentVo;
import shop.alien.lawyer.service.StoreCommentService;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 评论表 前端控制器
 *
 * @author ssk
 * @since 2025-01-02
 */
@Slf4j
@Api(tags = {"二期-评论/评价"})
@ApiSort(11)
@CrossOrigin
@RestController
@RequestMapping("/storeComment")
@RequiredArgsConstructor
public class LawyerStoreCommentController {

    private final StoreCommentService storeCommentService;

    @ApiOperation("评论/评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "businessId", value = "业务id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "businessType", value = "业务类型(1:订单评论, 2:动态社区评论, 3:活动评论, 4:店铺打卡评论, 5:订单评价, 6:订单评论的评论)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "replyStatus", value = "回复状态(0:全部, 1:已回复, 2:未回复)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "commentLevel", value = "评论等级(0:全部, 1:好评, 2:中评, 3:差评)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "days", value = "查询时间, 多少天前", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "phoneId", value = "消息标识", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userType", value = "评论的用户类型(0:商家, 其他:用户)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tagId", value = "标签id)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "hasImage", value = "是否有图片(0否/1是)", dataType = "Boolean", paramType = "query")
    })
    @GetMapping("/getList")
    public R<IPage<StoreCommentVo>> getList(Integer pageNum, Integer pageSize, Integer businessId, Integer businessType, Integer storeId, Integer replyStatus, Integer commentLevel, Integer days, String phoneId, Integer userType, Integer tagId,@RequestParam(required = false, defaultValue = "false") Boolean hasImage) {
        log.info("StoreCommentController.getList?pageNum={}&pageSize={}&businessId={}&businessType={}&storeId={}&replyStatus={}&commentLevel={}&days={}&phoneId={}&userType={}&tagId={}&hasImage={}", pageNum, pageSize, businessId, businessType, storeId, replyStatus, commentLevel, days, phoneId, userType, tagId, hasImage);
        return R.data(storeCommentService.getList(pageNum, pageSize, businessId, businessType, storeId, replyStatus, commentLevel, days, phoneId, userType, tagId, hasImage));
    }

    @ApiOperation("获取最新一条评论/评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businessId", value = "业务id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "businessType", value = "业务类型(1:订单评论, 2:动态社区评论, 3:活动评论, 4:店铺打卡评论, 5:订单评价)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userType", value = "用户类型(0:商家, 其他:用户)", dataType = "String", paramType = "query")
    })
    @GetMapping("/getOne")
    public R<StoreCommentVo> getOne(Integer businessId, Integer businessType, Integer storeId) {
        log.info("StoreCommentController.getOne?businessId={}&businessType={}&storeId={}", businessId, businessType, storeId);
        return R.data(storeCommentService.getOne(businessId, businessType, storeId));
    }

    @ApiOperation("评论/评价数量和评分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businessId", value = "业务id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "businessType", value = "业务类型(1:订单评论, 2:动态社区评论, 3:活动评论, 4:店铺打卡评论, 5:订单评价)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query")
    })
    @GetMapping("/getCommitCountAndScore")
    public R<Map<String, Object>> getCommitCountAndScore(Integer businessId, Integer businessType, Integer storeId, String phoneId, Integer days) {
        log.info("StoreCommentController.getCommitCountAndScore?businessId={}&businessType={}&storeId={}&phoneId={}&days={}", businessId, businessType, storeId, phoneId, days);
        return R.data(storeCommentService.getCommitCountAndScore(businessId, businessType, storeId, phoneId, days));
    }

    @ApiOperation(value = "新增评论(旧)", notes = "0:成功, 1:失败, 2:文本内容异常, 3:图片内容异常")
    @ApiImplicitParams({@ApiImplicitParam(name = "multipartRequest", value = "文件", dataType = "File", paramType = "query"),
            @ApiImplicitParam(name = "businessId", value = "业务id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "businessType", value = "业务类型(1:订单评论, 2:动态社区评论, 3:活动评论)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "replyId", value = "回复id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "commentContent", value = "评论内容", dataType = "String", paramType = "query")
    })
    @PostMapping("/userComment")
    public R<Integer> userComment(MultipartRequest multipartRequest,
                                  Integer businessId,
                                  Integer businessType,
                                  Integer storeId,
                                  Integer userId,
                                  Integer replyId,
                                  String commentContent) {
        log.info("StoreCommentController.userComment?businessId={}&businessType={}&storeId={}&userId={}&replyId={}&commentContent={}", businessId, businessType, storeId, userId, replyId, commentContent);
        Set<String> fileNameSet = multipartRequest.getMultiFileMap().keySet();
        log.info(String.valueOf(fileNameSet.size()));
        return R.data(storeCommentService.userComment(multipartRequest, businessId, businessType, storeId, userId, replyId, commentContent));
    }

    @ApiOperation(value = "新增或修改评论/评价", notes = "0:成功, 1:失败, 2:文本内容异常, 3:图片内容异常")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "multipartRequest", value = "文件", dataType = "File", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "主键", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "businessId", value = "业务id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "businessType", value = "业务类型(1:订单评论, 2:动态社区评论, 3:活动评论, 4:店铺打卡评论, 5:订单评价)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "replyId", value = "回复id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "commentContent", value = "评论内容", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "score", value = "评分", dataType = "Double", paramType = "query"),
            @ApiImplicitParam(name = "otherScore", value = "其他评分", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isAnonymous", value = "是否匿名(0:否(默认), 1:是)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "evaluationTags", value = "评价标签", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "phoneId", value = "用户id", dataType = "String", paramType = "query")
    })
    @PostMapping("/saveComment")
    public R<Integer> saveComment(MultipartRequest multipartRequest, Integer id, Integer businessId, Integer businessType, Integer storeId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous, String evaluationTags, String phoneId) {
        log.info("StoreCommentController.saveComment?id={}&businessId={}&businessType={}&storeId={}&userId={}&replyId={}&commentContent={}&score={}&otherScore={}&isAnonymous={}&evaluationTags={}&phoneId={}", id, businessId, businessType, storeId, userId, replyId, commentContent, score, otherScore, isAnonymous, evaluationTags, phoneId);
        Set<String> fileNameSet = multipartRequest.getMultiFileMap().keySet();
        log.info(String.valueOf(fileNameSet.size()));
        return R.data(storeCommentService.addComment(multipartRequest, id, businessId, businessType, storeId, userId, replyId, commentContent, score, otherScore, isAnonymous, evaluationTags, phoneId));
    }

    @ApiOperation(value = "新增或修改评论/评价(new)", notes = "0:成功, 1:失败, 2:文本内容异常, 3:图片内容异常")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "multipartRequest", value = "文件", dataType = "File", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "主键", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "businessId", value = "业务id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "businessType", value = "业务类型(1:订单评论, 2:动态社区评论, 3:活动评论, 4:店铺打卡评论, 5:订单评价)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "lawyerId", value = "律师id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "replyId", value = "回复id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "commentContent", value = "评论内容", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "score", value = "评分", dataType = "Double", paramType = "query"),
            @ApiImplicitParam(name = "otherScore", value = "其他评分", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isAnonymous", value = "是否匿名(0:否(默认), 1:是)", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "evaluationTags", value = "评价标签", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "phoneId", value = "用户id", dataType = "String", paramType = "query")
    })
    @PostMapping("/saveCommentNew")
    public R<Integer> saveCommentNew(MultipartRequest multipartRequest, Integer id, Integer businessId, Integer businessType, Integer storeId, Integer orderId, Integer lawyerId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous, String evaluationTags, String phoneId) {
        log.info("StoreCommentController.saveCommentNew?id={}&businessId={}&businessType={}&storeId={}&orderId={}&lawyerId={}&userId={}&replyId={}&commentContent={}&score={}&otherScore={}&isAnonymous={}&evaluationTags={}&phoneId={}", id, businessId, businessType, storeId, orderId, lawyerId, userId, replyId, commentContent, score, otherScore, isAnonymous, evaluationTags, phoneId);
        Set<String> fileNameSet = multipartRequest.getMultiFileMap().keySet();
        log.info(String.valueOf(fileNameSet.size()));
        return R.data(storeCommentService.addCommentNew(multipartRequest, id, businessId, businessType, storeId, orderId, lawyerId, userId, replyId, commentContent, score, otherScore, isAnonymous, evaluationTags, phoneId));
    }

    @ApiOperation(value = "回复率, 评价比例")
    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getCommitPercent")
    public R<StoreCommitPercentVo> getCommitPercent(@RequestParam("storeId") Integer storeId) {
        return R.data(storeCommentService.getCommitPercent(storeId));
    }

    @ApiOperation(value = "删除评论/评价")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "评论主键", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/delete")
    public R<Boolean> delete(Integer id) {
        if (storeCommentService.removeById(id)) {
            return R.success("删除成功");
        }
        return R.fail("删除失败");
    }

    @ApiOperation("未评价/已评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "1:未评价, 2:已评价", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query", required = true),
    })
    @GetMapping("/getCommentOrderPage")
    public R<IPage<LifeUserOrderCommentVo>> getCommentOrderPage(Integer pageNum, Integer pageSize, Integer type, String userId) {
        log.info("StoreCommentController.getCommentOrderPage?pageNum={}&pageSize={}&type={}&userId={}", pageNum, pageSize, type, userId);
        return R.data(storeCommentService.getCommentOrderPage(pageNum, pageSize, type, userId));
    }

    @ApiOperation("当前用户全部评价（店铺+律师）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "预留字段，传1或2均可", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", paramType = "query", required = true),
    })
    @GetMapping("/getUserAllCommentsPage")
    public R<IPage<LifeUserOrderCommentVo>> getUserAllCommentsPage(Integer pageNum, Integer pageSize, Integer type, Integer userId) {
        log.info("StoreCommentController.getUserAllCommentsPage?pageNum={}&pageSize={}&type={}&userId={}", pageNum, pageSize, type, userId);
        return R.data(storeCommentService.getUserAllCommentsPage(pageNum, pageSize, userId));
    }

    @ApiOperation("获取店铺评价计数统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getAppraiseCount")
    public R<StoreCommentCountVo> getAppraiseCount(@RequestParam("storeId") Integer storeId) {
        log.info("StoreCommentController.getAppraiseCount?storeId={}", storeId);
        return R.data(storeCommentService.getAppraiseCount(storeId));
    }

    // ==================== 订单评价相关接口（迁移自 OrderReviewController）====================

    @ApiOperation("创建订单评价（只有订单用户才能评价）")
    @ApiOperationSupport(order = 20)
    @PostMapping("/orderReview/create")
    public R<StoreComment> createOrderReview(@RequestBody OrderReviewDto reviewDto) {
        log.info("StoreCommentController.createOrderReview?reviewDto={}", reviewDto);
        if (reviewDto.getUserId() == null) {
            return R.fail("用户未登录");
        }
        return storeCommentService.createOrderReview(reviewDto);
    }

    @ApiOperation("获取评价详情（包含评论和回复）")
    @ApiOperationSupport(order = 21)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "评价ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "currentUserId", value = "用户ID", dataType = "int", paramType = "query", required = true)
    })
    @GetMapping("/orderReview/detail")
    public R<OrderReviewDetailVo> getOrderReviewDetail(
            @RequestParam(required = false) Integer orderId,
            @RequestParam(required = false) Integer currentUserId) {
        log.info("StoreCommentController.getOrderReviewDetail?reviewId={}, currentUserId={}", orderId, currentUserId);
        if (orderId == null) {
            return R.fail("订单id不为空");
        }
        return storeCommentService.getOrderReviewDetail(orderId, currentUserId);
    }

    @ApiOperation("点赞评价")
    @ApiOperationSupport(order = 22)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reviewId", value = "评价ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "query", required = true)
    })
    @PostMapping("/orderReview/like")
    public R<Boolean> likeOrderReview(@RequestBody StoreComment storeComment) {
        Integer reviewId = storeComment.getId();
        Integer userId = storeComment.getUserId();
        log.info("StoreCommentController.likeOrderReview?reviewId={}, userId={}", reviewId, userId);
        if (userId == null) {
            return R.fail("用户未登录");
        }
        if (reviewId == null) {
            return R.fail("评价ID不能为空");
        }
        return storeCommentService.likeOrderReview(reviewId, userId);
    }

    @ApiOperation("取消点赞评价")
    @ApiOperationSupport(order = 23)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reviewId", value = "评价ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "query", required = true)
    })
    @PostMapping("/orderReview/cancelLike")
    public R<Boolean> cancelLikeOrderReview(@RequestBody StoreComment storeComment) {
        Integer reviewId = storeComment.getId();
        Integer userId = storeComment.getUserId();
        log.info("StoreCommentController.cancelLikeOrderReview?reviewId={}, userId={}", reviewId, userId);
        if (userId == null) {
            return R.fail("用户未登录");
        }
        return storeCommentService.cancelLikeOrderReview(reviewId, userId);
    }

    @ApiOperation("分页查询评价列表")
    @ApiOperationSupport(order = 24)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数（默认1）", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "页容（默认10）", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "lawyerUserId", value = "律师用户ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "评价用户ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "currentUserId", value = "当前用户ID（用于判断是否已点赞）", dataType = "int", paramType = "query")
    })
    @GetMapping("/orderReview/list")
    public R<IPage<OrderReviewVo>> getOrderReviewList(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size,
            @RequestParam(required = false) Integer orderId,
            @RequestParam(required = false) Integer lawyerUserId,
            @RequestParam(required = false) Integer userId,
            @RequestParam(required = false) Integer currentUserId) {
        log.info("StoreCommentController.getOrderReviewList?page={}, size={}, orderId={}, lawyerUserId={}, userId={}, currentUserId={}",
                page, size, orderId, lawyerUserId, userId, currentUserId);
        return storeCommentService.getOrderReviewList(page, size, orderId, lawyerUserId, userId, currentUserId);
    }

    @ApiOperation("根据订单ID查询评价")
    @ApiOperationSupport(order = 25)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "currentUserId", value = "当前用户ID（用于判断是否已点赞）", dataType = "int", paramType = "query")
    })
    @GetMapping("/orderReview/getByOrderId")
    public R<OrderReviewVo> getOrderReviewByOrderId(
            @RequestParam Integer orderId,
            @RequestParam(required = false) Integer currentUserId) {
        log.info("StoreCommentController.getOrderReviewByOrderId?orderId={}, currentUserId={}", orderId, currentUserId);
        return storeCommentService.getOrderReviewByOrderId(orderId, currentUserId);
    }

    // ==================== 评价评论相关接口（迁移自 ReviewCommentController）====================

    @ApiOperation("创建评论（其他用户对评价的评论）")
    @ApiOperationSupport(order = 30)
    @PostMapping("/reviewComment/create")
    public R<StoreComment> createReviewComment(@RequestBody StoreComment comment) {
        log.info("StoreCommentController.createReviewComment?comment={}", comment);
        if (comment.getUserId() == null) {
            return R.fail("用户未登录");
        }
        return storeCommentService.createReviewComment(comment);
    }

    @ApiOperation("根据评价ID查询评论列表")
    @ApiOperationSupport(order = 31)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reviewId", value = "评价ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "currentUserId", value = "当前用户ID（用于判断是否已点赞）", dataType = "int", paramType = "query")
    })
    @GetMapping("/reviewComment/list")
    public R<List<ReviewCommentVo>> getReviewCommentListByReviewId(
            @RequestParam Integer reviewId,
            @RequestParam(required = false) Integer currentUserId) {
        log.info("StoreCommentController.getReviewCommentListByReviewId?reviewId={}, currentUserId={}", reviewId, currentUserId);
        return storeCommentService.getReviewCommentListByReviewId(reviewId, currentUserId);
    }

    @ApiOperation("点赞评论")
    @ApiOperationSupport(order = 32)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评论ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "query", required = true)
    })
    @PostMapping("/reviewComment/like")
    public R<Boolean> likeReviewComment(@RequestBody ReviewCommentRequestDto requestDto) {
        log.info("StoreCommentController.likeReviewComment?commentId={}, userId={}", requestDto.getCommentId(), requestDto.getUserId());
        if (requestDto.getUserId() == null) {
            return R.fail("用户未登录");
        }
        if (requestDto.getCommentId() == null) {
            return R.fail("评论ID不能为空");
        }
        return storeCommentService.likeReviewComment(requestDto);
    }

    @ApiOperation("取消点赞评论")
    @ApiOperationSupport(order = 33)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评论ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "query", required = true)
    })
    @PostMapping("/reviewComment/cancelLike")
    public R<Boolean> cancelLikeReviewComment(@RequestBody ReviewCommentRequestDto requestDto) {
        log.info("StoreCommentController.cancelLikeReviewComment?commentId={}, userId={}", requestDto.getCommentId(), requestDto.getUserId());
        if (requestDto.getUserId() == null) {
            return R.fail("用户未登录");
        }
        if (requestDto.getCommentId() == null) {
            return R.fail("评论ID不能为空");
        }
        return storeCommentService.cancelLikeReviewComment(requestDto);
    }

    @ApiOperation("创建回复（用户对评论的回复）")
    @ApiOperationSupport(order = 34)
    @PostMapping("/reviewComment/reply/create")
    public R<StoreComment> createReviewReply(@RequestBody ReviewReplyDto replyDto) {
        log.info("StoreCommentController.createReviewReply?replyDto={}", replyDto);
        if (replyDto.getUserId() == null) {
            return R.fail("用户未登录");
        }
        return storeCommentService.createReviewReply(replyDto);
    }

    @ApiOperation("根据首评ID查询回复列表")
    @ApiOperationSupport(order = 35)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "headId", value = "首评ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "currentUserId", value = "当前用户ID（用于判断是否已点赞）", dataType = "int", paramType = "query")
    })
    @GetMapping("/reviewComment/reply/list")
    public R<List<ReviewCommentVo>> getReviewReplyListByHeadId(
            @RequestParam Integer headId,
            @RequestParam(required = false) Integer currentUserId) {
        log.info("StoreCommentController.getReviewReplyListByHeadId?headId={}, currentUserId={}", headId, currentUserId);
        return storeCommentService.getReviewReplyListByHeadId(headId, currentUserId);
    }

    @ApiOperation("删除回复")
    @ApiOperationSupport(order = 36)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "replyId", value = "回复ID", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "int", paramType = "query", required = true)
    })
    @PostMapping("/reviewComment/reply/delete")
    public R<Boolean> deleteReviewReply(
            @RequestParam Integer replyId,
            @RequestParam Integer userId) {
        log.info("StoreCommentController.deleteReviewReply?replyId={}, userId={}", replyId, userId);
        if (userId == null) {
            return R.fail("用户未登录");
        }
        return storeCommentService.deleteReviewReply(replyId, userId);
    }
}
