import { prisma } from '../../models';

/**
 * 评论服务
 */
export class CommentsService {
  /**
   * 获取章节的所有评论
   */
  async getCommentsByChapterId(chapterId: number) {
    return await prisma.comment.findMany({
      where: { chapterId },
      orderBy: { createdAt: 'desc' },
    });
  }

  /**
   * 添加评论
   */
  async addComment(userId: number, chapterId: number, content: string, rating: number) {
    return await prisma.comment.create({
      data: {
        userId,
        chapterId,
        content,
        rating,
      },
    });
  }
}

export const commentsService = new CommentsService();
