import 'package:syncrow_app/features/app_layout/model/community_model.dart'; import 'package:syncrow_app/features/devices/model/room_model.dart'; class SpaceModel { final String id; final String name; final Community community; final List subspaces; SpaceModel({ required this.id, required this.name, required this.community, this.subspaces = const [], // Default to an empty list }); /// Converts the instance into JSON format. Map toJson() { return { 'id': id, 'spaceName': name, 'community': community.toJson(), 'subspaces': subspaces.map((room) => room.toJson()).toList(), }; } /// Factory constructor to create an instance from JSON. factory SpaceModel.fromJson(Map json) { final spaceData = json['space'] as Map? ?? {}; return SpaceModel( id: json['uuid'] ?? '', name: spaceData['spaceName'] ?? 'Unnamed Space', community: Community.fromJson(spaceData['community'] ?? {}), subspaces: (spaceData['subspaces'] as List?) ?.map((item) => SubSpaceModel.fromJson(item)) .toList() ?? [], ); } /// Helper method to parse a list of SpaceModel from JSON. static List fromJsonList(List jsonList) { return jsonList.map((item) => SpaceModel.fromJson(item)).toList(); } }