69 lines
1.8 KiB
Dart
69 lines
1.8 KiB
Dart
enum GroupType { group, direct }
|
|
|
|
class GroupModel {
|
|
final String id;
|
|
final String name;
|
|
final String? description;
|
|
final bool isActive;
|
|
final GroupType type;
|
|
final DateTime? createdAt;
|
|
final int memberCount;
|
|
|
|
const GroupModel({
|
|
required this.id,
|
|
required this.name,
|
|
this.description,
|
|
required this.isActive,
|
|
this.type = GroupType.group,
|
|
this.createdAt,
|
|
this.memberCount = 0,
|
|
});
|
|
|
|
factory GroupModel.fromJson(Map<String, dynamic> json) {
|
|
return GroupModel(
|
|
id: json['id'] as String,
|
|
name: json['name'] as String,
|
|
description: json['description'] as String?,
|
|
isActive: (json['is_active'] as bool?) ?? true,
|
|
type: GroupType.values.firstWhere(
|
|
(t) => t.name == (json['type'] as String? ?? 'group'),
|
|
orElse: () => GroupType.group,
|
|
),
|
|
createdAt: json['created_at'] != null
|
|
? DateTime.tryParse(json['created_at'] as String)
|
|
: null,
|
|
memberCount: (json['member_count'] as int?) ?? 0,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'name': name,
|
|
if (description != null) 'description': description,
|
|
'is_active': isActive,
|
|
'type': type.name,
|
|
if (createdAt != null) 'created_at': createdAt!.toIso8601String(),
|
|
'member_count': memberCount,
|
|
};
|
|
|
|
GroupModel copyWith({
|
|
String? id,
|
|
String? name,
|
|
String? description,
|
|
bool? isActive,
|
|
GroupType? type,
|
|
DateTime? createdAt,
|
|
int? memberCount,
|
|
}) {
|
|
return GroupModel(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
description: description ?? this.description,
|
|
isActive: isActive ?? this.isActive,
|
|
type: type ?? this.type,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
memberCount: memberCount ?? this.memberCount,
|
|
);
|
|
}
|
|
}
|