scheduleNotification method

Future<NotificationFailure?> scheduleNotification({
  1. required NotificationPayload payload,
  2. required DateTime scheduledTime,
  3. String? timeZone,
})

Schedules a notification for a specific date and time.

Implementation

Future<NotificationFailure?> scheduleNotification({
  required NotificationPayload payload,
  required DateTime scheduledTime,
  String? timeZone,
}) async {
  try {
    final tz.TZDateTime scheduledTZDateTime = _convertToTZDateTime(
      scheduledTime,
      timeZone,
    );

    if (scheduledTZDateTime.isBefore(tz.TZDateTime.now(tz.local))) {
      return NotificationFailure.invalidInput(
        details: 'Scheduled time must be in the future',
      );
    }

    // The actual scheduling would be handled by the concrete repository
    return null;
  } catch (e, stackTrace) {
    safeDebugLog('Failed to schedule notification: $e');
    return NotificationFailure.scheduling(
      details: e.toString(),
      stackTrace: stackTrace,
    );
  }
}