60 lines
1.3 KiB
Dart
60 lines
1.3 KiB
Dart
enum GroupType { public, private }
|
|
|
|
extension GroupTypeExtension on GroupType {
|
|
String get label {
|
|
switch (this) {
|
|
case GroupType.public:
|
|
return 'عمومی';
|
|
case GroupType.private:
|
|
return 'خصوصی';
|
|
}
|
|
}
|
|
}
|
|
|
|
class GroupModel {
|
|
final String id;
|
|
final String name;
|
|
final bool isActive;
|
|
final GroupType type;
|
|
|
|
const GroupModel({
|
|
required this.id,
|
|
required this.name,
|
|
required this.isActive,
|
|
this.type = GroupType.public,
|
|
});
|
|
|
|
factory GroupModel.fromJson(Map<String, dynamic> json) {
|
|
return GroupModel(
|
|
id: json['id'].toString(),
|
|
name: json['name'] as String,
|
|
isActive: (json['is_active'] as bool?) ?? true,
|
|
type: GroupType.values.firstWhere(
|
|
(t) => t.name == (json['type'] as String? ?? 'public'),
|
|
orElse: () => GroupType.public,
|
|
),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'name': name,
|
|
'is_active': isActive,
|
|
'type': type.name,
|
|
};
|
|
|
|
GroupModel copyWith({
|
|
String? id,
|
|
String? name,
|
|
bool? isActive,
|
|
GroupType? type,
|
|
}) {
|
|
return GroupModel(
|
|
id: id ?? this.id,
|
|
name: name ?? this.name,
|
|
isActive: isActive ?? this.isActive,
|
|
type: type ?? this.type,
|
|
);
|
|
}
|
|
}
|