/**
 * @ai-summary Daily scheduled job to process maintenance notifications
 * @ai-context Runs at 8 AM daily to check schedules and send notifications
 */

import { logger } from '../../../core/logging/logger';
import { NotificationsService } from '../domain/notifications.service';

export async function processScheduledNotifications(): Promise<void> {
  const startTime = Date.now();
  const service = new NotificationsService();

  try {
    logger.info('Starting scheduled notification processing');

    const results = await service.processNotifications();

    logger.info('Notification processing completed', {
      durationMs: Date.now() - startTime,
      processed: results.processed,
      emailsSent: results.emailsSent,
      inAppCreated: results.inAppCreated,
      errorCount: results.errors.length
    });

    if (results.errors.length > 0) {
      logger.warn('Some notifications failed', {
        errors: results.errors.slice(0, 10) // Log first 10 errors
      });
    }
  } catch (error) {
    logger.error('Notification processing failed', {
      error: error instanceof Error ? error.message : String(error),
      durationMs: Date.now() - startTime
    });
    throw error;
  }
}
