import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export default defineEventHandler(async (event) => {
  try {
    // Get all published processes that haven't been started
    const processes = await prisma.process.findMany({
      where: {
        status: 'published',
        cases: {
          none: {
            status: 'active'
          }
        }
      },
      select: {
        id: true,
        name: true,
        description: true,
        status: true,
        createdAt: true,
        updatedAt: true
      },
      orderBy: {
        updatedAt: 'desc'
      }
    });

    return {
      success: true,
      data: processes
    };
  } catch (error) {
    console.error('Error fetching pending processes:', error);
    return {
      success: false,
      error: 'Failed to fetch pending processes'
    };
  }
}); 