import 'package:equatable/equatable.dart';

class SpaceModel extends Equatable {
  final String uuid;
  final DateTime? createdAt;
  final DateTime? updatedAt;
  final String spaceName;
  final String icon;
  final List<SpaceModel> children;
  final SpaceModel? parent;

  const SpaceModel({
    required this.uuid,
    required this.createdAt,
    required this.updatedAt,
    required this.spaceName,
    required this.icon,
    required this.children,
    required this.parent,
  });

  factory SpaceModel.fromJson(Map<String, dynamic> json) {
    return SpaceModel(
      uuid: json['uuid'] as String? ?? '',
      createdAt: DateTime.tryParse(json['createdAt'] as String? ?? ''),
      updatedAt: DateTime.tryParse(json['updatedAt'] as String? ?? ''),
      spaceName: json['spaceName'] as String? ?? '',
      icon: json['icon'] as String? ?? 'assets/icons/location_icon.svg',
      children: (json['children'] as List<dynamic>?)
              ?.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
              .toList() ??
          [],
      parent: json['parent'] != null
          ? SpaceModel.fromJson(json['parent'] as Map<String, dynamic>)
          : null,
    );
  }

  @override
  List<Object?> get props => [uuid, spaceName, icon, children];
}
