CategoryModel

mail@pastecode.io avatar
unknown
dart
2 years ago
6.2 kB
3
Indexable
Never
import 'dart:convert';

import 'package:base_architecture/data_layer/models/api_models/books_models/book_model.dart';
import 'package:base_architecture/data_layer/models/api_models/books_models/pivot_model.dart';
import 'package:base_architecture/data_layer/models/api_models/name_decode_model.dart';
import 'package:base_architecture/data_layer/models/api_models/translated_name_model.dart';

class CategoriesModel {
  CategoriesModel({this.data});

  CategoriesModel.fromJson(Map<String, dynamic> json) {
    data = json['data'] != null
        ? new CategoriesModelData.fromJson(json['data'])
        : null;
  }
  CategoriesModelData? data;

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.data != null) {
      data['data'] = this.data!.toJson();
    }
    return data;
  }
}

class CategoriesModelData {
  CategoriesModelData({
    this.categories,
    this.mainCategories,
    this.contributor,
  });

  CategoriesModelData.fromJson(Map<String, dynamic> json) {
    if (json['categories'] != null) {
      categories = <CategoriesItem>[];
      json['categories'].forEach((v) {
        categories!.add(CategoriesItem.fromJson(v));
      });
    }
    if (json['main_categories'] != null) {
      mainCategories = <MainCategoriesTabs>[];
      json['main_categories'].forEach((v) {
        mainCategories!.add(new MainCategoriesTabs.fromJson(v));
      });
    }
    contributor = json['contributor'] != null
        ? new Contributor.fromJson(json['contributor'])
        : null;
  }
  List<CategoriesItem>? categories;
  List<MainCategoriesTabs>? mainCategories;
  Contributor? contributor;

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (categories != null) {
      data['categories'] = categories!.map((v) => v.toJson()).toList();
    }
    if (this.mainCategories != null) {
      data['main_categories'] =
          this.mainCategories!.map((v) => v.toJson()).toList();
    }
    if (this.contributor != null) {
      data['contributor'] = this.contributor!.toJson();
    }
    return data;
  }
}

class CategoriesItem {
  CategoriesItem({
    this.id,
    this.translatedName,
    this.imageFullPath,
    this.soundFullPath,
    this.mainCategoryBooks,
  });

  CategoriesItem.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    translatedName = json['translated_name'] != null
        ? TranslatedNameModel.fromJson(json['translated_name'])
        : null;
    imageFullPath = json['image_full_path'];
    soundFullPath = json['sound_full_path'];
    if (json['books'] != null) {
      mainCategoryBooks = <Book>[];
      json['books'].forEach((v) {
        mainCategoryBooks!.add(Book.fromJson(v));
      });
    }
  }
  int? id;
  TranslatedNameModel? translatedName;
  String? imageFullPath;
  String? soundFullPath;
  List<Book>? mainCategoryBooks;

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['translated_name'] = translatedName;
    data['image_full_path'] = imageFullPath;
    data['sound_full_path'] = soundFullPath;
    if (mainCategoryBooks != null) {
      data['books'] = mainCategoryBooks!.map((v) => v.toJson()).toList();
    }
    return data;
  }

  static Map<String, dynamic> toMap(CategoriesItem categoriesItem) => {
        'id': categoriesItem.id,
        'translated_name': categoriesItem.translatedName,
        'image_full_path': categoriesItem.imageFullPath,
        'sound_full_path': categoriesItem.soundFullPath,
        'books': categoriesItem.mainCategoryBooks,
      };
}

class MainCategoriesTabs {
  int? id;
  String? imageFullPath;
  String? soundFullPath;
  String? nameAr;
  String? nameEn;
  String? nameHe;

  MainCategoriesTabs(
      {this.id,
      this.imageFullPath,
      this.soundFullPath,
      this.nameAr,
      this.nameEn,
      this.nameHe});

  MainCategoriesTabs.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    imageFullPath = json['image_full_path'];
    soundFullPath = json['sound_full_path'];
    nameAr = json['name_ar'];
    nameEn = json['name_en'];
    nameHe = json['name_he'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['image_full_path'] = this.imageFullPath;
    data['sound_full_path'] = this.soundFullPath;
    data['name_ar'] = this.nameAr;
    data['name_en'] = this.nameEn;
    data['name_he'] = this.nameHe;
    return data;
  }
}
class Contributor {
  int? id;
  List<FullNameDecode>? fullNameDecode;
  String? imageFullPath;
  String? body;
  int? numFollower;
  List<RoleContributor>? roleContributor;

  Contributor(
      {this.id,
      this.fullNameDecode,
      this.imageFullPath,
      this.body,
      this.numFollower});

  Contributor.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    if (json['full_name_decode'] != null) {
      fullNameDecode = <FullNameDecode>[];
      json['full_name_decode'].forEach((v) {
        fullNameDecode!.add(new FullNameDecode.fromJson(v));
      });
    }
    imageFullPath = json['image_full_path'];
    body = json['body'];
    numFollower = json['num_follower'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    if (this.fullNameDecode != null) {
      data['full_name_decode'] =
          this.fullNameDecode!.map((v) => v.toJson()).toList();
    }
    data['image_full_path'] = this.imageFullPath;
    data['body'] = this.body;
    data['num_follower'] = this.numFollower;
    return data;
  }
}
class RoleContributor {
  String? name;
  Pivot? pivot;

  RoleContributor({this.name, this.pivot});

  RoleContributor.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    pivot = json['pivot'] != null ? new Pivot.fromJson(json['pivot']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    if (this.pivot != null) {
      data['pivot'] = this.pivot!.toJson();
    }
    return data;
  }
}