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

class RoomModel {
  final String? id;
  final String? name;
  final SpaceType type;
  List<DeviceModel>? devices;

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

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'type': type,
      'devices': devices,
    };
  }

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