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

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

Map<String, dynamic> $NewsfeedNewsEntityToJson(NewsfeedNewsEntity 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 NewsfeedNewsEntityExtension on NewsfeedNewsEntity {
  NewsfeedNewsEntity copyWith({
    int? count,
    int? page,
    int? limit,
    int? countPage,
    List<NewsfeedNewsList>? list,
  }) {
    return NewsfeedNewsEntity()
      ..count = count ?? this.count
      ..page = page ?? this.page
      ..limit = limit ?? this.limit
      ..countPage = countPage ?? this.countPage
      ..list = list ?? this.list;
  }
}

NewsfeedNewsList $NewsfeedNewsListFromJson(Map<String, dynamic> json) {
  final NewsfeedNewsList newsfeedNewsList = NewsfeedNewsList();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    newsfeedNewsList.id = id;
  }
  final String? content = jsonConvert.convert<String>(json['content']);
  if (content != null) {
    newsfeedNewsList.content = content;
  }
  final List<String>? resources = (json['resources'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<String>(e) as String).toList();
  if (resources != null) {
    newsfeedNewsList.resources = resources;
  }
  final int? likesCount = jsonConvert.convert<int>(json['likes_count']);
  if (likesCount != null) {
    newsfeedNewsList.likesCount = likesCount;
  }
  final int? commentsCount = jsonConvert.convert<int>(json['comments_count']);
  if (commentsCount != null) {
    newsfeedNewsList.commentsCount = commentsCount;
  }
  final bool? liked = jsonConvert.convert<bool>(json['liked']);
  if (liked != null) {
    newsfeedNewsList.liked = liked;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    newsfeedNewsList.createdAt = createdAt;
  }
  final NewsfeedNewsListAccount? account = jsonConvert.convert<NewsfeedNewsListAccount>(json['account']);
  if (account != null) {
    newsfeedNewsList.account = account;
  }
  return newsfeedNewsList;
}

Map<String, dynamic> $NewsfeedNewsListToJson(NewsfeedNewsList entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['content'] = entity.content;
  data['resources'] = entity.resources;
  data['likes_count'] = entity.likesCount;
  data['comments_count'] = entity.commentsCount;
  data['liked'] = entity.liked;
  data['created_at'] = entity.createdAt;
  data['account'] = entity.account?.toJson();
  return data;
}

extension NewsfeedNewsListExtension on NewsfeedNewsList {
  NewsfeedNewsList copyWith({
    int? id,
    String? content,
    List<String>? resources,
    int? likesCount,
    int? commentsCount,
    bool? liked,
    String? createdAt,
    NewsfeedNewsListAccount? account,
  }) {
    return NewsfeedNewsList()
      ..id = id ?? this.id
      ..content = content ?? this.content
      ..resources = resources ?? this.resources
      ..likesCount = likesCount ?? this.likesCount
      ..commentsCount = commentsCount ?? this.commentsCount
      ..liked = liked ?? this.liked
      ..createdAt = createdAt ?? this.createdAt
      ..account = account ?? this.account;
  }
}

NewsfeedNewsListAccount $NewsfeedNewsListAccountFromJson(Map<String, dynamic> json) {
  final NewsfeedNewsListAccount newsfeedNewsListAccount = NewsfeedNewsListAccount();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    newsfeedNewsListAccount.id = id;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    newsfeedNewsListAccount.name = name;
  }
  final String? avatar = jsonConvert.convert<String>(json['avatar']);
  if (avatar != null) {
    newsfeedNewsListAccount.avatar = avatar;
  }
  final bool? followed = jsonConvert.convert<bool>(json['followed']);
  if (followed != null) {
    newsfeedNewsListAccount.followed = followed;
  }
  return newsfeedNewsListAccount;
}

Map<String, dynamic> $NewsfeedNewsListAccountToJson(NewsfeedNewsListAccount entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['name'] = entity.name;
  data['avatar'] = entity.avatar;
  data['followed'] = entity.followed;
  return data;
}

extension NewsfeedNewsListAccountExtension on NewsfeedNewsListAccount {
  NewsfeedNewsListAccount copyWith({
    int? id,
    String? name,
    String? avatar,
    bool? followed,
  }) {
    return NewsfeedNewsListAccount()
      ..id = id ?? this.id
      ..name = name ?? this.name
      ..avatar = avatar ?? this.avatar
      ..followed = followed ?? this.followed;
  }
}