import 'package:initial_folder/models/subcategories_model.dart';

class CategoriesModel {
  CategoriesModel({
    this.id,
    this.nameCategory,
    this.slugCategory,
    this.parentCategory,
    this.fontAwesomeClass,
    this.subCategories,
    this.subId,
  });

  final String? id;
  final String? nameCategory;
  final String? slugCategory;
  final String? parentCategory;
  final String? fontAwesomeClass;
  final String? subId;
  List<SubCategoryModel>? subCategories;

  factory CategoriesModel.fromJson(Map<String, dynamic> json) {
    List<dynamic> subCategoriesJson = json['subcategories'] ?? [];
    List<SubCategoryModel> subCategories = subCategoriesJson
        .map((subCategoryJson) => SubCategoryModel.fromJson(subCategoryJson))
        .toList();

    return CategoriesModel(
      id: json["id"],
      nameCategory: json["name_category"],
      slugCategory: json["slug_category"],
      parentCategory: json["parent_category"],
      fontAwesomeClass: json["font_awesome_class"],
      subId: json["sub_category_id"],
      subCategories: subCategories,
    );
  }

  Map<String, dynamic> toJson() => {
        "id": id,
        "name_category": nameCategory,
        "slug_category": slugCategory,
        "parent_category": parentCategory,
        "font_awesome_class": fontAwesomeClass,
        "sub_category_id": subId
      };
}
