@@ -2,6 +2,7 @@ import 'package:built_collection/built_collection.dart';
2
2
import 'package:built_value/built_value.dart' ;
3
3
import 'package:built_value/serializer.dart' ;
4
4
import 'package:flutter/foundation.dart' ;
5
+ import 'package:invoiceninja_flutter/data/models/entities.dart' ;
5
6
6
7
part 'import_model.g.dart' ;
7
8
@@ -19,31 +20,48 @@ abstract class PreImportResponse
19
20
20
21
String get hash;
21
22
22
- BuiltList <BuiltList <String >> get headers;
23
+ BuiltMap <String ,PreImportResponseEntityDetails > get mappings;
24
+
25
+ static Serializer <PreImportResponse > get serializer =>
26
+ _$preImportResponseSerializer;
27
+ }
28
+
29
+ abstract class PreImportResponseEntityDetails
30
+ implements Built <PreImportResponseEntityDetails , PreImportResponseEntityDetailsBuilder > {
31
+ factory PreImportResponseEntityDetails () {
32
+ return _$PreImportResponseEntityDetails ._();
33
+ }
34
+
35
+ PreImportResponseEntityDetails ._();
36
+
37
+ @override
38
+ @memoized
39
+ int get hashCode;
23
40
24
41
BuiltList <String > get available;
42
+ BuiltList <BuiltList <String >> get headers;
25
43
26
44
BuiltList <String > get fields1 =>
27
45
headers.isEmpty ? BuiltList <String >() : headers[0 ];
28
46
29
47
BuiltList <String > get fields2 =>
30
48
headers.length < 2 ? BuiltList <String >() : headers[1 ];
31
49
32
- static Serializer <PreImportResponse > get serializer =>
33
- _$preImportResponseSerializer ;
50
+ static Serializer <PreImportResponseEntityDetails > get serializer =>
51
+ _$preImportResponseEntityDetailsSerializer ;
34
52
}
35
53
36
54
abstract class ImportRequest
37
55
implements Built <ImportRequest , ImportRequestBuilder > {
38
56
factory ImportRequest ({
39
57
@required String hash,
40
- @required String entityType ,
58
+ @required String importType ,
41
59
@required bool skipHeader,
42
- @required BuiltMap <int , String > columnMap,
60
+ @required BuiltMap <String , BuiltMap < int , String > > columnMap,
43
61
}) {
44
62
return _$ImportRequest ._(
45
63
hash: hash,
46
- entityType : entityType ,
64
+ importType : importType ,
47
65
skipHeader: skipHeader,
48
66
columnMap: columnMap,
49
67
);
@@ -57,14 +75,58 @@ abstract class ImportRequest
57
75
58
76
String get hash;
59
77
60
- @BuiltValueField (wireName: 'entity_type ' )
61
- String get entityType ;
78
+ @BuiltValueField (wireName: 'import_type ' )
79
+ String get importType ;
62
80
63
81
@BuiltValueField (wireName: 'skip_header' )
64
82
bool get skipHeader;
65
83
66
84
@BuiltValueField (wireName: 'column_map' )
67
- BuiltMap <int , String > get columnMap;
85
+ BuiltMap <String , BuiltMap <int , String >> get columnMap;
86
+
87
+ // This needed so the builder factory for BuiltMap<int, String> is auto-created.
88
+ @nullable
89
+ @BuiltValueField (wireName: 'dummy_field' )
90
+ BuiltMap <int , String > get dummy;
68
91
69
92
static Serializer <ImportRequest > get serializer => _$importRequestSerializer;
70
93
}
94
+
95
+ class ImportType extends EnumClass {
96
+ const ImportType ._(String name) : super (name);
97
+
98
+ static Serializer <ImportType > get serializer => _$importTypeSerializer;
99
+
100
+ static const ImportType csv = _$csv;
101
+ static const ImportType freshbooks = _$freshbooks;
102
+ static const ImportType invoice2go = _$invoice2go;
103
+
104
+ static const ImportType invoicely = _$invoicely;
105
+ static const ImportType waveaccounting = _$waveaccounting;
106
+ static const ImportType zoho = _$zoho;
107
+
108
+ static BuiltSet <ImportType > get values => _$typeValues;
109
+
110
+ List <String > get uploadParts {
111
+ switch (this ) {
112
+ case ImportType .csv:
113
+ return [
114
+ EntityType .client.toString (),
115
+ EntityType .invoice.toString (),
116
+ EntityType .payment.toString (),
117
+ EntityType .product.toString (),
118
+ EntityType .vendor.toString (),
119
+ EntityType .expense.toString (),
120
+ ];
121
+ case ImportType .freshbooks:
122
+ return [
123
+ EntityType .client.toString (),
124
+ EntityType .payment.toString (),
125
+ ];
126
+ default :
127
+ return [];
128
+ }
129
+ }
130
+
131
+ static ImportType valueOf (String name) => _$typeValueOf (name);
132
+ }
0 commit comments