forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolder.dart
More file actions
121 lines (110 loc) · 3.22 KB
/
Copy pathfolder.dart
File metadata and controls
121 lines (110 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Phase 4.1 SKIPPED — has copyWith + computed accessors, so not typedef'd here.
// Folder exposes copyWith(), a computed colorValue getter, and a custom toString();
// per the refactor rules, files with copyWith need manual care and are excluded.
import 'package:flutter/material.dart';
import 'package:omi/backend/schema/gen/action_items_folders_wire.g.dart' as wire;
class Folder {
final String id;
final String name;
final String? description;
final String color;
final String icon;
final DateTime createdAt;
final DateTime updatedAt;
final int order;
final bool isDefault;
final bool isSystem;
final String? categoryMapping;
final int conversationCount;
Folder({
required this.id,
required this.name,
this.description,
required this.color,
required this.icon,
required this.createdAt,
required this.updatedAt,
required this.order,
required this.isDefault,
required this.isSystem,
this.categoryMapping,
required this.conversationCount,
});
factory Folder.fromJson(Map<String, dynamic> json) {
return Folder.fromGenerated(wire.GeneratedFolder.fromJson(json));
}
factory Folder.fromGenerated(wire.GeneratedFolder generated) {
return Folder(
id: generated.id,
name: generated.name,
description: generated.description,
color: generated.color,
icon: generated.icon,
createdAt: generated.createdAt,
updatedAt: generated.updatedAt,
order: generated.order,
isDefault: generated.isDefault,
isSystem: generated.isSystem,
categoryMapping: generated.categoryMapping,
conversationCount: generated.conversationCount,
);
}
wire.GeneratedFolder toGenerated() {
return wire.GeneratedFolder(
id: id,
name: name,
description: description,
color: color,
icon: icon,
createdAt: createdAt,
updatedAt: updatedAt,
order: order,
isDefault: isDefault,
isSystem: isSystem,
categoryMapping: categoryMapping,
conversationCount: conversationCount,
);
}
Map<String, dynamic> toJson() {
return toGenerated().toJson();
}
Color get colorValue {
try {
final hex = color.replaceFirst('#', '');
return Color(int.parse('FF$hex', radix: 16));
} catch (e) {
return const Color(0xFF6B7280);
}
}
@override
String toString() => 'Folder(id: $id, name: $name, count: $conversationCount)';
Folder copyWith({
String? id,
String? name,
String? description,
String? color,
String? icon,
DateTime? createdAt,
DateTime? updatedAt,
int? order,
bool? isDefault,
bool? isSystem,
String? categoryMapping,
int? conversationCount,
}) {
return Folder(
id: id ?? this.id,
name: name ?? this.name,
description: description ?? this.description,
color: color ?? this.color,
icon: icon ?? this.icon,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
order: order ?? this.order,
isDefault: isDefault ?? this.isDefault,
isSystem: isSystem ?? this.isSystem,
categoryMapping: categoryMapping ?? this.categoryMapping,
conversationCount: conversationCount ?? this.conversationCount,
);
}
}