deliver method

Implementation

@override
Future<ChartExportDeliveryResult> deliver(ChartExportFile file) async {
  final limit = maxAttempts < 1 ? 1 : maxAttempts;
  final errors = <String>[];

  for (var attempt = 1; attempt <= limit; attempt++) {
    final result = await _attemptDeliver(file, attempt, errors);
    if (result.success) {
      return ChartExportDeliveryResult.success(
        result.file ?? file,
        attempts: attempt,
        retryErrors: errors,
      );
    }

    errors.add(result.errorText ?? 'Delivery failed.');
    final canRetry = attempt < limit && _shouldRetry(result, attempt, limit);
    if (!canRetry) {
      return ChartExportDeliveryResult.failure(
        file: result.file ?? file,
        error: result.error ?? 'Delivery failed.',
        stackTrace: result.stackTrace,
        attempts: attempt,
        retryErrors: errors,
      );
    }

    await _waitBeforeRetry(result, attempt, limit);
  }

  return ChartExportDeliveryResult.failure(
    file: file,
    error: 'Delivery failed.',
    attempts: limit,
    retryErrors: errors,
  );
}