import 'dart:developer'; import 'package:test_sa/models/base.dart'; import 'package:test_sa/models/new_models/floor.dart'; class Building extends Base { Building({ this.id, this.value, this.floors, String? name, }) : super(identifier: id?.toString() ?? '', name: name); // Handle potential null id Building.fromJson(dynamic json) { id = json['id'] ?? json['buildingId']; identifier = id?.toString() ?? ''; name = json['name'] ?? json['buildingName']; value = json['value']; if (json['floors'] != null) { floors = []; json['floors'].forEach((v) { floors!.add(Floor.fromJson(v)); }); } else if (json['assetInventoryFloors'] != null) { floors = []; json['assetInventoryFloors'].forEach((v) { floors!.add(Floor.fromJson(v)); }); } } num? id; num? value; List? floors; Building copyWith({ num? id, String? name, num? value, List? floors, }) => Building( id: id ?? this.id, name: name ?? this.name, value: value ?? this.value, floors: floors ?? this.floors, ); Map toJson({bool addFloor = true}) { final map = {}; map['id'] = id; map['name'] = name; map['value'] = value; if (addFloor) { if (floors != null) { map['floors'] = floors!.map((v) => v.toJson()).toList(); } } return map; } }