import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import 'news.dart';

part 'region_news.freezed.dart';
part 'region_news.g.dart';

@freezed
class RegionNews with _$RegionNews {
  const factory RegionNews({
    required List<News> news,
    String? nextPage,
  }) = _RegionNews;

  factory RegionNews.fromJson(Map<String, dynamic> json) =>
      _$RegionNewsFromJson(json);
}

// old manual implementation:

// class RegionNews {
//   List<News> news;
//   String newStoriesCountLink;
//   String type;
//   String? nextPage;
//   RegionNews({
//     required this.news,
//     required this.newStoriesCountLink,
//     required this.type,
//     this.nextPage,
//   });

//   RegionNews copyWith({
//     List<News>? news,
//     String? newStoriesCountLink,
//     String? type,
//     String? nextPage,
//   }) {
//     return RegionNews(
//       news: news ?? this.news,
//       newStoriesCountLink: newStoriesCountLink ?? this.newStoriesCountLink,
//       type: type ?? this.type,
//       nextPage: nextPage ?? this.nextPage,
//     );
//   }

//   Map<String, dynamic> toMap() {
//     return {
//       'news': news.map((x) => x.toMap()).toList(),
//       'newStoriesCountLink': newStoriesCountLink,
//       'type': type,
//       'nextPage': nextPage,
//     };
//   }

//   factory RegionNews.fromMap(Map<String, dynamic> map) {
//     return RegionNews(
//       news: List<News>.from(map['news']?.map((x) => News.fromMap(x))),
//       newStoriesCountLink: map['newStoriesCountLink'] ?? '',
//       type: map['type'] ?? '',
//       nextPage: map['nextPage'],
//     );
//   }

//   String toJson() => json.encode(toMap());

//   factory RegionNews.fromJson(String source) =>
//       RegionNews.fromMap(json.decode(source));

//   @override
//   String toString() {
//     return 'RegionNews(news: $news, newStoriesCountLink: $newStoriesCountLink, type: $type, nextPage: $nextPage)';
//   }

//   @override
//   bool operator ==(Object other) {
//     if (identical(this, other)) return true;

//     return other is RegionNews &&
//         listEquals(other.news, news) &&
//         other.newStoriesCountLink == newStoriesCountLink &&
//         other.type == type &&
//         other.nextPage == nextPage;
//   }

//   @override
//   int get hashCode {
//     return news.hashCode ^
//         newStoriesCountLink.hashCode ^
//         type.hashCode ^
//         nextPage.hashCode;
//   }
// }
