import prisma from '~/lib/prisma';

export default defineEventHandler(async (event) => {
  const id = event.context.params?.id;

  try {
    const article = await prisma.article.findUnique({
      where: { id },
      include: { comments: true }, 
    });

    if (!article) {
      return {
        success: false,
        data: null,
        message: 'Article not found.',
      };
    }

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