import 'package:syncrow_app/features/devices/model/device_model.dart';

class SubSpaceModel {
  final String? id;
  final String? name;
  List<DeviceModel>? devices;

  SubSpaceModel({
    required this.id,
    required this.name,
    required this.devices,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'devices': devices?.map((device) => device.toJson()).toList(),
    };
  }

  factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
    List<DeviceModel> devices = [];
    if (json['devices'] != null) {
      for (var device in json['devices']) {
        devices.add(DeviceModel.fromJson(device));
      }
    }
    return SubSpaceModel(
      id: json['uuid'],
      name: json['subspaceName'],
      devices: devices,
    );
  }
}
