import '../../models/search_results.dart';
import 'connection_mastodon_extensions.dart';
import 'timeline_entry_mastodon_extensions.dart';

extension SearchResultMastodonExtensions on SearchResults {
  static SearchResults fromJson(Map<String, dynamic> json) {
    final accounts = (json['accounts'] as List<dynamic>? ?? [])
        .map((j) => ConnectionMastodonExtensions.fromJson(j))
        .toList();

    final statuses = (json['statuses'] as List<dynamic>? ?? [])
        .map((j) => TimelineEntryMastodonExtensions.fromJson(j))
        .toList();

    final hashtags = (json['hashtags'] as List<dynamic>? ?? [])
        .map((j) => j.toString())
        .toList();

    return SearchResults(
      accounts: accounts,
      statuses: statuses,
      hashtags: hashtags,
    );
  }
}
