import prisma from '~/lib/prisma';

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

  if (!id) {
    return {
      success: false,
      message: 'Invalid comment ID.',
    };
  }

  try {
    await prisma.comment.delete({
      where: { id },
    });

    return {
      success: true,
      message: 'Comment deleted successfully',
    };
  } catch (error) {
    console.error('Error deleting comment:', error);
    return {
      success: false,
      message: 'An error occurred while deleting the comment',
      error: error.message,
    };
  }
});
