class GroupMember {
  final String userId;
  final String firstName;
  final String pseudo; // Pseudo du membre (par défaut = prénom)
  final String role; // 'admin' ou 'member'
  final DateTime joinedAt;

  GroupMember({
    required this.userId,
    required this.firstName,
    String? pseudo,
    this.role = 'member',
    DateTime? joinedAt,
  })  : pseudo = pseudo ?? firstName, // Par défaut, pseudo = prénom
        joinedAt = joinedAt ?? DateTime.now();

  factory GroupMember.fromMap(Map<String, dynamic> map, String userId) {
    return GroupMember(
      userId: userId,
      firstName: map['firstName'] ?? '',
      pseudo: map['pseudo'] ?? map['firstName'] ?? '',
      role: map['role'] ?? 'member',
      joinedAt: DateTime.fromMillisecondsSinceEpoch(map['joinedAt'] ?? 0),
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'firstName': firstName,
      'pseudo': pseudo,
      'role': role,
      'joinedAt': joinedAt.millisecondsSinceEpoch,
    };
  }

  GroupMember copyWith({
    String? userId,
    String? firstName,
    String? pseudo,
    String? role,
    DateTime? joinedAt,
  }) {
    return GroupMember(
      userId: userId ?? this.userId,
      firstName: firstName ?? this.firstName,
      pseudo: pseudo ?? this.pseudo,
      role: role ?? this.role,
      joinedAt: joinedAt ?? this.joinedAt,
    );
  }
}