class Hospital { int? id; int? customerCode; String? name; List? buildings; Hospital({ this.id, this.customerCode, this.name, this.buildings, }); factory Hospital.fromJson(Map parsedJson) { List buildings = []; if (parsedJson['buildings'] != null) { buildings = []; parsedJson['buildings'].forEach((v) { buildings.add(Buildings.fromJson(v)); }); } return Hospital(id: parsedJson["id"], name: parsedJson["custName"], customerCode: parsedJson["customerCode"], buildings: buildings); } factory Hospital.fromHospital(Hospital? hospital) { return Hospital(id: hospital?.id, name: hospital?.name, customerCode: hospital?.customerCode, buildings: hospital?.buildings); } Map toMap() { return {'id': id, 'customerCode': customerCode, 'custName': name, "buildings": []}; } } // class Data { // int id; // int customerCode; // String custName; // List buildings; // // Data({this.id, this.customerCode, this.custName, this.buildings}); // // Data.fromJson(Map json) { // id = json['id']; // customerCode = json['customerCode']; // custName = json['custName']; // if (json['buildings'] != null) { // buildings = new List(); // json['buildings'].forEach((v) { // buildings.add(new Buildings.fromJson(v)); // }); // } // } // // Map toJson() { // final Map data = new Map(); // data['id'] = this.id; // data['customerCode'] = this.customerCode; // data['custName'] = this.custName; // if (this.buildings != null) { // data['buildings'] = this.buildings.map((v) => v.toJson()).toList(); // } // return data; // } // } class Buildings { int? id; String? name; int? value; List? floors; Buildings({this.id, this.name, this.value, this.floors}); Buildings.fromJson(Map json) { id = json['id']; name = json['name']; value = json['value']; if (json['floors'] != null) { floors = []; json['floors'].forEach((v) { floors!.add(Floors.fromJson(v)); }); } } Map toJson({bool includeFloors = true}) { final Map data = {}; data['id'] = id; data['name'] = name; data['value'] = value; if (floors != null && includeFloors) { data['floors'] = floors!.map((v) => v.toJson()).toList(); } return data; } } class Floors { int? id; String? name; int? value; List? departments; Floors({this.id, this.name, this.value, this.departments}); Floors.fromJson(Map json) { id = json['id']; name = json['name']; value = json['value']; if (json['departments'] != null) { departments = []; json['departments'].forEach((v) { departments!.add(Departments.fromJson(v)); }); } } Map toJson({bool includeDepartments = true}) { final Map data = {}; data['id'] = id; data['name'] = name; data['value'] = value; if (departments != null && includeDepartments) { data['departments'] = departments!.map((v) => v.toJson()).toList(); } return data; } } class Departments { int? id; String? name; Departments({this.id, this.name}); Departments.fromJson(Map json) { id = json['id']; name = json['name']; } Map toJson() { final Map data = {}; data['id'] = id; data['name'] = name; return data; } }