import 'package:domain/generated/json/base/json_convert_content.dart';
import 'package:domain/entity/latest_news_page_entity.dart';

LatestNewsPageEntity $LatestNewsPageEntityFromJson(Map<String, dynamic> json) {
  final LatestNewsPageEntity latestNewsPageEntity = LatestNewsPageEntity();
  final int? count = jsonConvert.convert<int>(json['count']);
  if (count != null) {
    latestNewsPageEntity.count = count;
  }
  final int? page = jsonConvert.convert<int>(json['page']);
  if (page != null) {
    latestNewsPageEntity.page = page;
  }
  final int? limit = jsonConvert.convert<int>(json['limit']);
  if (limit != null) {
    latestNewsPageEntity.limit = limit;
  }
  final int? countPage = jsonConvert.convert<int>(json['count_page']);
  if (countPage != null) {
    latestNewsPageEntity.countPage = countPage;
  }
  final List<LatestNewsList>? list = (json['list'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<LatestNewsList>(e) as LatestNewsList).toList();
  if (list != null) {
    latestNewsPageEntity.list = list;
  }
  return latestNewsPageEntity;
}

Map<String, dynamic> $LatestNewsPageEntityToJson(LatestNewsPageEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['count'] = entity.count;
  data['page'] = entity.page;
  data['limit'] = entity.limit;
  data['count_page'] = entity.countPage;
  data['list'] = entity.list?.map((v) => v.toJson()).toList();
  return data;
}

extension LatestNewsPageEntityExtension on LatestNewsPageEntity {
  LatestNewsPageEntity copyWith({
    int? count,
    int? page,
    int? limit,
    int? countPage,
    List<LatestNewsList>? list,
  }) {
    return LatestNewsPageEntity()
      ..count = count ?? this.count
      ..page = page ?? this.page
      ..limit = limit ?? this.limit
      ..countPage = countPage ?? this.countPage
      ..list = list ?? this.list;
  }
}

LatestNewsList $LatestNewsListFromJson(Map<String, dynamic> json) {
  final LatestNewsList latestNewsList = LatestNewsList();
  final String? id = jsonConvert.convert<String>(json['id']);
  if (id != null) {
    latestNewsList.id = id;
  }
  final int? type = jsonConvert.convert<int>(json['type']);
  if (type != null) {
    latestNewsList.type = type;
  }
  final String? title = jsonConvert.convert<String>(json['title']);
  if (title != null) {
    latestNewsList.title = title;
  }
  final String? coverImage = jsonConvert.convert<String>(json['cover_image']);
  if (coverImage != null) {
    latestNewsList.coverImage = coverImage;
  }
  final String? content = jsonConvert.convert<String>(json['content']);
  if (content != null) {
    latestNewsList.content = content;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    latestNewsList.createdAt = createdAt;
  }
  return latestNewsList;
}

Map<String, dynamic> $LatestNewsListToJson(LatestNewsList entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['type'] = entity.type;
  data['title'] = entity.title;
  data['cover_image'] = entity.coverImage;
  data['content'] = entity.content;
  data['created_at'] = entity.createdAt;
  return data;
}

extension LatestNewsListExtension on LatestNewsList {
  LatestNewsList copyWith({
    String? id,
    int? type,
    String? title,
    String? coverImage,
    String? content,
    String? createdAt,
  }) {
    return LatestNewsList()
      ..id = id ?? this.id
      ..type = type ?? this.type
      ..title = title ?? this.title
      ..coverImage = coverImage ?? this.coverImage
      ..content = content ?? this.content
      ..createdAt = createdAt ?? this.createdAt;
  }
}