44
55use Carbon \Carbon ;
66use CodebarAg \DocuWare \Support \ParseValue ;
7+ use Illuminate \Support \Arr ;
78use Illuminate \Support \Collection ;
89use Illuminate \Support \Str ;
910
1011final class Document
1112{
1213 public static function fromJson (array $ data ): self
1314 {
14- $ fields = self ::convertFields (collect ($ data ['Fields ' ]));
15+ $ suggestions = Arr::has ($ data , 'Suggestions ' )
16+ ? self ::convertSuggestions (collect (Arr::get ($ data , 'Suggestions ' )))
17+ : null ;
18+
19+ $ fields = Arr::has ($ data , 'Fields ' )
20+ ? self ::convertFields (collect (Arr::get ($ data , 'Fields ' )))
21+ : null ;
1522
1623 return new self (
1724 id: $ data ['Id ' ],
@@ -21,9 +28,11 @@ public static function fromJson(array $data): self
2128 extension: $ fields ['DWEXTENSION ' ]->value ,
2229 content_type: $ data ['ContentType ' ],
2330 file_cabinet_id: $ data ['FileCabinetId ' ],
31+ intellixTrust: Arr::get ($ data , 'IntellixTrust ' ),
2432 created_at: ParseValue::date ($ data ['CreatedAt ' ]),
2533 updated_at: ParseValue::date ($ data ['LastModified ' ]),
2634 fields: $ fields ,
35+ suggestions: $ suggestions ,
2736 );
2837 }
2938
@@ -34,6 +43,13 @@ protected static function convertFields(Collection $fields): Collection
3443 });
3544 }
3645
46+ protected static function convertSuggestions (Collection $ suggestions ): Collection |null
47+ {
48+ return $ suggestions ->mapWithKeys (function (array $ suggestion ) {
49+ return [$ suggestion ['DBName ' ] => SuggestionField::fromJson ($ suggestion )];
50+ });
51+ }
52+
3753 public function __construct (
3854 public int $ id ,
3955 public int $ file_size ,
@@ -42,9 +58,11 @@ public function __construct(
4258 public string |null $ extension ,
4359 public string $ content_type ,
4460 public string $ file_cabinet_id ,
61+ public string |null $ intellixTrust ,
4562 public Carbon $ created_at ,
4663 public Carbon $ updated_at ,
47- public Collection $ fields ,
64+ public Collection |null $ fields ,
65+ public Collection |null $ suggestions ,
4866 ) {
4967 }
5068
@@ -94,24 +112,28 @@ public static function fake(
94112 ?string $ extension = null ,
95113 ?string $ content_type = null ,
96114 ?string $ file_cabinet_id = null ,
115+ ?string $ intellixTrust = null ,
97116 ?Carbon $ created_at = null ,
98117 ?Carbon $ updated_at = null ,
99118 ?Collection $ fields = null ,
119+ ?Collection $ suggestions = null ,
100120 ): self {
101- return new static (
121+ return new self (
102122 id: $ id ?? random_int (1 , 999999 ),
103123 file_size: $ file_size ?? random_int (1000 , 999999 ),
104124 total_pages: $ total_pages ?? random_int (1 , 100 ),
105125 title: $ title ?? 'Fake Title ' ,
106126 extension: $ extension ?? '.pdf ' ,
107127 content_type: $ content_type ?? 'application/pdf ' ,
108128 file_cabinet_id: $ file_cabinet_id ?? (string ) Str::uuid (),
129+ intellixTrust: $ intellixTrust ?? 'Red ' ,
109130 created_at: $ created_at ?? now ()->subDay (),
110131 updated_at: $ updated_at ?? now (),
111132 fields: $ fields ?? collect ([
112133 DocumentField::fake (),
113134 DocumentField::fake (),
114135 ]),
136+ suggestions: $ suggestions ?? null
115137 );
116138 }
117139}
0 commit comments