migrateToPod method

Future<void> migrateToPod()

Migrates data from SharedPreferences to POD.

Implementation

Future<void> migrateToPod() async {
  try {
    // Load data from SharedPreferences.

    final toWatch = await _fallbackService.getToWatch();
    final watched = await _fallbackService.getWatched();

    // Migrate ratings.

    final Map<String, double> ratings = {};
    for (final movie in [...toWatch, ...watched]) {
      final rating = await _fallbackService.getPersonalRating(movie);
      if (rating != null) {
        ratings[movie.id.toString()] = rating;
      }
    }

    // Migrate comments.

    final Map<String, String> comments = {};
    for (final movie in [...toWatch, ...watched]) {
      final comment = await _fallbackService.getMovieComments(movie);
      if (comment != null) {
        comments[movie.id.toString()] = comment;
      }
    }

    // Save to POD.

    await _saveToWatchToPod(toWatch);
    await _saveWatchedToPod(watched);
    await _saveRatingsToPod(ratings);
    // Skip saving comments to old format - we use individual movie files now
    // await _saveCommentsToPod(comments);
  } catch (e) {
    debugPrint('Failed to migrate data to POD: $e');
    rethrow;
  }
}