import { prisma } from './prisma';

export async function cleanupPendingOrders() {
  try {
    const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);

    const result = await prisma.order.deleteMany({
      where: {
        status: 'PENDING',
        createdAt: { lt: twentyFourHoursAgo },
      },
    });

    if (result.count > 0) {
      console.log(`✓ Cleaned up ${result.count} incomplete orders older than 24 hours`);
    }

    return result.count;
  } catch (error) {
    console.error('Error cleaning up pending orders:', error);
    return 0;
  }
}
