import 'package:equatable/equatable.dart';
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';

class CommunityModel extends Equatable {
  final String uuid;
  final String name;
  final DateTime createdAt;
  final DateTime updatedAt;
  final String description;
  final String externalId;
  final List<SpaceModel> spaces;

  const CommunityModel({
    required this.uuid,
    required this.name,
    required this.createdAt,
    required this.updatedAt,
    required this.description,
    required this.externalId,
    required this.spaces,
  });

  factory CommunityModel.fromJson(Map<String, dynamic> json) {
    return CommunityModel(
      uuid: json['uuid'] as String,
      name: json['name'] as String,
      createdAt: DateTime.parse(json['createdAt'] as String),
      updatedAt: DateTime.parse(json['updatedAt'] as String),
      description: json['description'] as String,
      externalId: json['externalId']?.toString() ?? '',
      spaces: (json['spaces'] as List<dynamic>? ?? <dynamic>[])
          .map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
          .toList(),
    );
  }
  static List<CommunityModel> fromJsonList(List<dynamic> json) {
    return json
        .map((e) => CommunityModel.fromJson(e as Map<String, dynamic>))
        .toList();
  }

  @override
  List<Object?> get props => [uuid, name, spaces];
}
