import prisma from '~/lib/prisma';

export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { articleId } = query;

  try {
    const comments = await prisma.comment.findMany({
      where: articleId ? { articleId: String(articleId) } : undefined,
    });

    return {
      success: true,
      data: comments,
    };
  } catch (error) {
    console.error('Error fetching comments:', error);
    return {
      success: false,
      message: 'An error occurred while fetching comments',
      error: error.message,
    };
  }
});
