class DeviceSubspace {
  final String uuid;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String subspaceName;
  final bool disabled;

  DeviceSubspace({
    required this.uuid,
    this.createdAt,
    this.updatedAt,
    required this.subspaceName,
    required this.disabled,
  });

  factory DeviceSubspace.fromJson(Map<String, dynamic> json) {
    return DeviceSubspace(
      uuid: json['uuid'] as String,
      createdAt: json['createdAt'] != null
          ? DateTime.tryParse(json['createdAt'].toString())
          : null,
      updatedAt: json['updatedAt'] != null
          ? DateTime.tryParse(json['updatedAt'].toString())
          : null,
      subspaceName: json['subspaceName'] as String,
      disabled: json['disabled'] as bool,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'uuid': uuid,
      'createdAt': createdAt?.toIso8601String(),
      'updatedAt': updatedAt?.toIso8601String(),
      'subspaceName': subspaceName,
      'disabled': disabled,
    };
  }

  static List<DeviceSubspace> listFromJson(List<dynamic> jsonList) {
    return jsonList.map((json) => DeviceSubspace.fromJson(json)).toList();
  }

  static List<Map<String, dynamic>> listToJson(List<DeviceSubspace> subspaces) {
    return subspaces.map((subspace) => subspace.toJson()).toList();
  }

  DeviceSubspace copyWith({
    String? uuid,
    DateTime? createdAt,
    DateTime? updatedAt,
    String? subspaceName,
    bool? disabled,
  }) {
    return DeviceSubspace(
      uuid: uuid ?? this.uuid,
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
      subspaceName: subspaceName ?? this.subspaceName,
      disabled: disabled ?? this.disabled,
    );
  }
}
