import prisma from '~/lib/prisma';

export default defineEventHandler(async (event) => {
  try {
    const articles = await prisma.article.findMany({
      include: { comments: true }, 
    });

    if (!articles || articles.length === 0) {
      return {
        success: false,
        data: null,
        message: 'No articles found.',
      };
    }

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