import 'dart:convert'; T? asT(dynamic value) { if (value is T) { return value; } return null; } class ComicRelatedModel { ComicRelatedModel({ required this.authorComics, required this.themeComics, required this.novels, }); factory ComicRelatedModel.fromJson(Map json) { final List? authorComics = json['author_comics'] is List ? [] : null; if (authorComics != null) { for (final dynamic item in json['author_comics']!) { if (item != null) { authorComics.add(ComicRelatedAuthorModel.fromJson( asT>(item)!)); } } } final List? themeComics = json['theme_comics'] is List ? [] : null; if (themeComics != null) { for (final dynamic item in json['theme_comics']!) { if (item != null) { themeComics.add( ComicRelatedItemModel.fromJson(asT>(item)!)); } } } final List? novels = json['novels'] is List ? [] : null; if (novels != null) { for (final dynamic item in json['novels']!) { if (item != null) { novels.add( ComicRelatedItemModel.fromJson(asT>(item)!)); } } } return ComicRelatedModel( authorComics: authorComics!, themeComics: themeComics!, novels: novels!, ); } List authorComics; List themeComics; List novels; @override String toString() { return jsonEncode(this); } Map toJson() => { 'author_comics': authorComics, 'theme_comics': themeComics, 'novels': novels, }; } class ComicRelatedAuthorModel { ComicRelatedAuthorModel({ required this.authorName, required this.authorId, required this.data, }); factory ComicRelatedAuthorModel.fromJson(Map json) { final List? data = json['data'] is List ? [] : null; if (data != null) { for (final dynamic item in json['data']!) { if (item != null) { data.add( ComicRelatedItemModel.fromJson(asT>(item)!)); } } } return ComicRelatedAuthorModel( authorName: asT(json['author_name'])!, authorId: asT(json['author_id'])!, data: data!, ); } String authorName; int authorId; List data; @override String toString() { return jsonEncode(this); } Map toJson() => { 'author_name': authorName, 'author_id': authorId, 'data': data, }; } class ComicRelatedItemModel { ComicRelatedItemModel({ required this.id, required this.name, required this.cover, required this.status, }); factory ComicRelatedItemModel.fromJson(Map json) => ComicRelatedItemModel( id: asT(json['id'])!, name: asT(json['name'])!, cover: asT(json['cover'])!, status: asT(json['status'])!, ); int id; String name; String cover; String status; @override String toString() { return jsonEncode(this); } Map toJson() => { 'id': id, 'name': name, 'cover': cover, 'status': status, }; }