cmtraceopen-parser 0.1.1

Parse ConfigMgr/SCCM, Intune, CBS, DISM, Panther, MSI, and PSADT logs with format auto-detection, severity classification, and Windows error-code lookup. Pure Rust, no I/O, native + wasm32.
Documentation
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
use serde::{Deserialize, Deserializer, Serialize, Serializer};

macro_rules! raw_preserving_string_enum {
    (
        $(#[$meta:meta])*
        pub enum $name:ident {
            $($variant:ident => $wire_value:literal),+ $(,)?
        }
    ) => {
        $(#[$meta])*
        #[derive(Debug, Clone, PartialEq, Eq)]
        pub enum $name {
            $($variant,)+
            Unknown(String),
        }

        impl Serialize for $name {
            fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
            where
                S: Serializer,
            {
                let value = match self {
                    $(Self::$variant => $wire_value,)+
                    Self::Unknown(raw) => raw.as_str(),
                };

                serializer.serialize_str(value)
            }
        }

        impl<'de> Deserialize<'de> for $name {
            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
            where
                D: Deserializer<'de>,
            {
                let raw = String::deserialize(deserializer)?;
                Ok(match raw.as_str() {
                    $($wire_value => Self::$variant,)+
                    _ => Self::Unknown(raw),
                })
            }
        }
    };
}

pub const ESP_DIAGNOSTICS_SCHEMA_VERSION: u32 = 1;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspScenario {
    Unknown,
    AutopilotV1,
    ExistingDeviceJson,
    EspOnly,
    AutopilotDevicePreparationV2,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspPhase {
    NotStarted,
    DevicePreparation,
    DeviceSetup,
    AccountSetup,
    Completed,
    Failed,
    Unknown,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspTrackedKind {
    Msi,
    Office,
    ModernApp,
    Win32App,
    Policy,
    ScepCertificate,
    PlatformScript,
    DevicePreparationWorkload,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspNormalizedStatus {
    NotStarted,
    NotInstalled,
    Initialized,
    Pending,
    Downloading,
    Downloaded,
    Installing,
    InProgress,
    Processed,
    Succeeded,
    Failed,
    Skipped,
    Uninstalled,
    RebootRequired,
    Cancelled,
    Unknown,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspArtifactStatus {
    Available,
    Missing,
    PermissionDenied,
    ParseFailed,
    Unsupported,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspCorrelationConfidence {
    Exact,
    Strong,
    Temporal,
    Uncorrelated,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspTimestampKind {
    Utc,
    Offset,
    Local,
    Unspecified,
    Invalid,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspSourceKind {
    Registry,
    Json,
    EventLog,
    ImeLog,
    DeploymentLog,
    Process,
    System,
    DeliveryOptimization,
    Graph,
    Coverage,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspSensitivity {
    Public,
    Sensitive,
    Restricted,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspClassifiedString {
    pub value: String,
    pub sensitivity: EspSensitivity,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspParseState {
    Parsed,
    Raw,
    Malformed,
    Unsupported,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspSourceAccessState {
    Available,
    Missing,
    PermissionDenied,
    Failed,
    Unsupported,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspScope {
    Device,
    User,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspSessionKind {
    Classic,
    DevicePreparationV2,
}

raw_preserving_string_enum! {
    pub enum EspJoinMode {
        Entra => "entra",
        HybridEntra => "hybridEntra",
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspFindingSeverity {
    Info,
    Warning,
    Error,
    Blocker,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspFindingConfidence {
    Low,
    Medium,
    High,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspTimelineKind {
    ProfileDownload,
    OfflineDomainJoin,
    Registration,
    Workload,
    DeliveryOptimization,
    Coverage,
    Process,
    Other,
}

raw_preserving_string_enum! {
    pub enum EspGraphAssignmentIntent {
        Required => "required",
        Available => "available",
        Uninstall => "uninstall",
    }
}

raw_preserving_string_enum! {
    pub enum EspGraphTargetKind {
        AllDevices => "allDevices",
        AllUsers => "allUsers",
        Group => "group",
        Filter => "filter",
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspGraphTargeting {
    Declared,
    Effective,
}

raw_preserving_string_enum! {
    pub enum EspGraphPolicyKind {
        DeviceConfiguration => "deviceConfiguration",
        Compliance => "compliance",
        ConfigurationPolicy => "configurationPolicy",
        ScepCertificate => "scepCertificate",
    }
}

raw_preserving_string_enum! {
    pub enum EspGraphScriptKind {
        PlatformScript => "platformScript",
        Remediation => "remediation",
    }
}

raw_preserving_string_enum! {
    pub enum EspGraphObservationSection {
        ManagedDevice => "managedDevice",
        AutopilotIdentity => "autopilotIdentity",
        DeploymentProfile => "deploymentProfile",
        EnrollmentConfiguration => "enrollmentConfiguration",
        App => "app",
        Policy => "policy",
        Script => "script",
    }
}

raw_preserving_string_enum! {
    pub enum EspGraphPolicyStatusDetailKind {
        App => "app",
        Policy => "policy",
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspDeliveryOptimizationEventKind {
    DownloadStarted,
    DownloadCompleted,
}

raw_preserving_string_enum! {
    pub enum GraphSectionStatus {
        Available => "available",
        NotFound => "notFound",
        PermissionDenied => "permissionDenied",
        Failed => "failed",
        Skipped => "skipped",
        Cancelled => "cancelled",
    }
}

raw_preserving_string_enum! {
    pub enum GraphApiVersion {
        V1_0 => "v1.0",
        Beta => "beta",
        NotRequested => "notRequested",
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum EspRawStatus {
    Number(i64),
    Text(String),
    Other(serde_json::Value),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspObservationValue {
    Text(String),
    Integer(i64),
    Unsigned(u64),
    Boolean(bool),
    StringList(Vec<String>),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum EspSystemFact {
    OsVersion(String),
    OsBuild(String),
    Manufacturer(String),
    Model(String),
    SerialNumber(String),
    TpmVersion(String),
    Hostname(String),
    EntraDeviceId(String),
    TenantId(String),
    JoinMode(EspJoinMode),
    Elevation(EspElevationState),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspTimestamp {
    pub raw_text: String,
    pub original_offset: Option<String>,
    pub normalized_utc: Option<String>,
    pub kind: EspTimestampKind,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspEvidenceRef {
    pub evidence_id: String,
    pub source_artifact_id: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspRegistryProvenance {
    pub hive: String,
    pub key: String,
    pub value_name: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspEventProvenance {
    pub channel: String,
    pub event_id: u32,
    pub record_id: Option<u64>,
    pub named_data: Vec<EspNamedValue>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspEvidenceProvenance {
    pub source_kind: EspSourceKind,
    pub source_artifact_id: String,
    pub file_path: Option<String>,
    pub line_number: Option<u64>,
    pub record_number: Option<u64>,
    pub registry: Option<EspRegistryProvenance>,
    pub event: Option<EspEventProvenance>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspObservationContext {
    pub evidence_ref: EspEvidenceRef,
    pub provenance: EspEvidenceProvenance,
    pub source_timestamp: Option<EspTimestamp>,
    pub observed_at_utc: String,
    pub sensitivity: EspSensitivity,
    pub parse_state: EspParseState,
    pub access_state: EspSourceAccessState,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspStatusDetail {
    pub raw: EspRawStatus,
    pub normalized: EspNormalizedStatus,
    pub display: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspStatus {
    pub raw: EspRawStatus,
    pub normalized: EspNormalizedStatus,
    pub display: String,
    pub detail: Option<EspStatusDetail>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspErrorCode {
    pub raw: String,
    pub decimal: Option<i64>,
    pub hex: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspNamedValue {
    pub name: String,
    pub value: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspElevationState {
    pub is_elevated: bool,
    pub restart_supported: bool,
    pub restricted_sources: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspIdentityEvidence {
    pub device_name: Option<String>,
    pub managed_device_id: Option<String>,
    pub entra_device_id: Option<String>,
    pub entdm_id: Option<EspClassifiedString>,
    pub tenant_id: Option<EspClassifiedString>,
    pub tenant_domain: Option<EspClassifiedString>,
    pub user_principal_name: Option<EspClassifiedString>,
    pub serial_number: Option<EspClassifiedString>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspOobeConfig {
    pub raw_mask: u64,
    pub skip_keyboard: bool,
    pub enable_patch_download: bool,
    pub skip_windows_upgrade_ux: bool,
    pub aad_tpm_required: bool,
    pub aad_device_authentication: bool,
    pub tpm_attestation: bool,
    pub skip_eula: bool,
    pub skip_oem_registration: bool,
    pub skip_express_settings: bool,
    pub disallow_admin: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspDevicePreparationEvidence {
    pub agent_download_timeout_seconds: Option<u64>,
    pub page_timeout_seconds: Option<u64>,
    pub allow_skip_on_failure: Option<bool>,
    pub allow_diagnostics: Option<bool>,
    pub script_ids: Vec<String>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspProfileEvidence {
    pub profile_name: Option<String>,
    pub deployment_profile_id: Option<String>,
    pub correlation_id: Option<String>,
    pub tenant_domain: Option<EspClassifiedString>,
    pub tenant_id: Option<EspClassifiedString>,
    pub oobe_config: Option<EspOobeConfig>,
    pub profile_download_time: Option<EspTimestamp>,
    pub join_mode: Option<EspJoinMode>,
    pub odj_applied: Option<bool>,
    pub skip_domain_connectivity_check: Option<bool>,
    pub device_preparation: Option<EspDevicePreparationEvidence>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspEnrollmentSettings {
    pub device_esp_enabled: Option<bool>,
    pub user_esp_enabled: Option<bool>,
    pub timeout_seconds: Option<u64>,
    pub blocking: Option<bool>,
    pub allow_reset: Option<bool>,
    pub allow_retry: Option<bool>,
    pub continue_anyway: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspEnrollmentEvidence {
    pub enrollment_id: String,
    pub provider_id: Option<String>,
    pub tenant_id: Option<EspClassifiedString>,
    pub user_principal_name: Option<EspClassifiedString>,
    pub entdm_id: Option<EspClassifiedString>,
    pub settings: EspEnrollmentSettings,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspSession {
    pub session_id: String,
    pub kind: EspSessionKind,
    pub scope: EspScope,
    pub user_sid: Option<EspClassifiedString>,
    pub started_at: Option<EspTimestamp>,
    pub ended_at: Option<EspTimestamp>,
    pub phase: EspPhase,
    pub is_latest: bool,
    pub workload_ids: Vec<String>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspWorkloadTimestamps {
    pub first_observed: EspTimestamp,
    pub started: Option<EspTimestamp>,
    pub ended: Option<EspTimestamp>,
    pub last_updated: Option<EspTimestamp>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspWorkload {
    pub workload_id: String,
    pub session_id: String,
    pub kind: EspTrackedKind,
    pub scope: EspScope,
    pub raw_identifier: String,
    pub display_name: Option<String>,
    pub status: EspStatus,
    pub timestamps: EspWorkloadTimestamps,
    pub exit_code: Option<EspErrorCode>,
    pub enforcement_error_code: Option<EspErrorCode>,
    pub blocking: Option<bool>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspNodeCacheEntry {
    pub index: u64,
    pub node_uri: String,
    pub expected_value: Option<String>,
    pub sensitivity: EspSensitivity,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspRegistrationEvent {
    pub event_id: u32,
    pub record_id: Option<u64>,
    pub status: EspStatus,
    pub message: String,
    pub timestamp: EspTimestamp,
    pub named_data: Vec<EspNamedValue>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspDeliveryOptimizationTransfer {
    pub transfer_id: String,
    pub kind: EspDeliveryOptimizationEventKind,
    pub content_id: Option<String>,
    pub app_id: Option<String>,
    pub timestamp: EspTimestamp,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct EspDeliveryOptimizationEvidence {
    pub download_http_bytes: u64,
    pub download_lan_bytes: u64,
    pub download_cache_host_bytes: u64,
    pub peer_share_percent: Option<f64>,
    pub connected_cache_share_percent: Option<f64>,
    pub transfers: Vec<EspDeliveryOptimizationTransfer>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspHardwareEvidence {
    pub os_version: Option<String>,
    pub os_build: Option<String>,
    pub manufacturer: Option<String>,
    pub model: Option<String>,
    pub serial_number: Option<EspClassifiedString>,
    pub tpm_version: Option<String>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspTimelineEntry {
    pub entry_id: String,
    pub timestamp: EspTimestamp,
    pub kind: EspTimelineKind,
    pub title: String,
    pub detail: Option<String>,
    pub status: Option<EspStatus>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspDiagnosticFinding {
    pub finding_id: String,
    pub severity: EspFindingSeverity,
    pub confidence: EspFindingConfidence,
    pub title: String,
    pub summary: String,
    pub recommended_checks: Vec<String>,
    pub evidence: Vec<EspEvidenceRef>,
    pub coverage_gap_ids: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspArtifactCoverage {
    pub artifact_id: String,
    pub family: String,
    pub status: EspArtifactStatus,
    pub detail: Option<String>,
    pub observed_at_utc: String,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspRawEvidenceRecord {
    pub record_id: String,
    pub provenance: EspEvidenceProvenance,
    pub source_timestamp: Option<EspTimestamp>,
    pub observed_at_utc: String,
    pub raw_value: EspObservationValue,
    pub sensitivity: EspSensitivity,
    pub parse_state: EspParseState,
    pub access_state: EspSourceAccessState,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspRegistryObservation {
    pub context: EspObservationContext,
    pub hive: String,
    pub key: String,
    pub value_name: String,
    pub value: EspObservationValue,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspJsonObservation {
    pub context: EspObservationContext,
    pub document_type: String,
    pub json_pointer: String,
    pub value: EspObservationValue,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspEventLogObservation {
    pub context: EspObservationContext,
    pub channel: String,
    pub event_id: u32,
    pub record_id: Option<u64>,
    pub named_data: Vec<EspNamedValue>,
    pub message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspImeObservation {
    pub context: EspObservationContext,
    pub component: Option<String>,
    pub message: String,
    pub app_id: Option<String>,
    pub status: Option<EspStatus>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspDeploymentLogObservation {
    pub context: EspObservationContext,
    pub component: Option<String>,
    pub message: String,
    pub product_code: Option<String>,
    pub log_path: Option<String>,
    pub status: Option<EspStatus>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspProcessObservation {
    pub context: EspObservationContext,
    pub pid: u32,
    pub process_start_time: EspTimestamp,
    pub parent_pid: Option<u32>,
    pub executable_name: String,
    pub sanitized_command_line: Option<String>,
    pub referenced_log_path: Option<String>,
    pub app_id: Option<String>,
    pub product_code: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspSystemObservation {
    pub context: EspObservationContext,
    pub fact: EspSystemFact,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspDeliveryOptimizationObservation {
    pub context: EspObservationContext,
    pub kind: EspDeliveryOptimizationEventKind,
    pub content_id: Option<String>,
    pub app_id: Option<String>,
    pub http_bytes: Option<u64>,
    pub lan_bytes: Option<u64>,
    pub cache_host_bytes: Option<u64>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphObservation {
    pub context: EspObservationContext,
    pub section: EspGraphObservationSection,
    pub api_version: GraphApiVersion,
    pub record_id: String,
    pub display_name: Option<String>,
    pub status: Option<EspStatus>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspInstallerCorrelation {
    pub correlation_id: String,
    pub workload_id: Option<String>,
    pub confidence: EspCorrelationConfidence,
    pub reason: String,
    pub candidate_workload_ids: Vec<String>,
    pub process_observations: Vec<EspProcessObservation>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct EspDiagnosticsSnapshot {
    pub schema_version: u32,
    pub scenario: EspScenario,
    pub phase: EspPhase,
    pub generated_at_utc: String,
    pub elevation: EspElevationState,
    pub identity: EspIdentityEvidence,
    pub profile: Option<EspProfileEvidence>,
    pub enrollments: Vec<EspEnrollmentEvidence>,
    pub sessions: Vec<EspSession>,
    pub workloads: Vec<EspWorkload>,
    pub installer_correlations: Vec<EspInstallerCorrelation>,
    pub node_cache: Vec<EspNodeCacheEntry>,
    pub registration_events: Vec<EspRegistrationEvent>,
    pub delivery_optimization: Option<EspDeliveryOptimizationEvidence>,
    pub hardware: Option<EspHardwareEvidence>,
    pub activity: Vec<EspTimelineEntry>,
    pub findings: Vec<EspDiagnosticFinding>,
    pub coverage: Vec<EspArtifactCoverage>,
    pub raw_evidence: Vec<EspRawEvidenceRecord>,
    pub graph: Option<EspGraphOverlay>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct GraphSectionError {
    pub code: String,
    pub message: String,
    pub request_id: Option<String>,
    pub blocked_by: Option<String>,
    pub retry_after_seconds: Option<u64>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct GraphSection<T> {
    pub status: GraphSectionStatus,
    pub required_scope: Option<String>,
    pub api_version: GraphApiVersion,
    pub data: Option<T>,
    pub error: Option<GraphSectionError>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphManagedDevice {
    pub managed_device_id: String,
    pub entra_device_id: Option<String>,
    pub serial_number: Option<EspClassifiedString>,
    pub device_name: Option<String>,
    pub user_id: Option<String>,
    pub user_principal_name: Option<EspClassifiedString>,
    pub tenant_id: Option<EspClassifiedString>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphDeviceMatch {
    pub selected: Option<EspGraphManagedDevice>,
    pub candidates: Vec<EspGraphManagedDevice>,
    pub match_basis: Option<String>,
    pub confidence: EspCorrelationConfidence,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphAutopilotIdentity {
    pub autopilot_device_id: String,
    pub entra_device_id: Option<String>,
    pub serial_number: Option<EspClassifiedString>,
    pub deployment_profile_id: Option<String>,
    pub group_tag: Option<String>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphDeploymentProfile {
    pub profile_id: String,
    pub display_name: Option<String>,
    pub join_mode: Option<EspJoinMode>,
    pub selected_mobile_app_ids: Vec<String>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphAssignment {
    pub assignment_id: String,
    pub target_id: Option<String>,
    pub filter_id: Option<String>,
    pub intent: EspGraphAssignmentIntent,
    pub target_kind: EspGraphTargetKind,
    pub targeting: EspGraphTargeting,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphPolicyStatusDetail {
    pub status_detail_id: String,
    pub related_object_id: Option<String>,
    pub display_name: Option<String>,
    pub kind: EspGraphPolicyStatusDetailKind,
    pub status: EspStatus,
    #[serde(default)]
    pub tracked_on_enrollment_status: Option<bool>,
    pub correlation_confidence: EspCorrelationConfidence,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphAutopilotEvent {
    pub event_id: String,
    pub managed_device_id: Option<String>,
    #[serde(default)]
    pub enrollment_configuration_id: Option<String>,
    pub event_time: Option<EspTimestamp>,
    pub deployment_state: EspStatus,
    pub policy_status_details: Vec<EspGraphPolicyStatusDetail>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphEnrollmentConfiguration {
    pub configuration_id: String,
    pub display_name: Option<String>,
    #[serde(default)]
    pub show_installation_progress: Option<bool>,
    pub device_esp_enabled: Option<bool>,
    pub user_esp_enabled: Option<bool>,
    #[serde(default)]
    pub disable_user_status_tracking_after_first_user: Option<bool>,
    pub timeout_minutes: Option<u64>,
    pub selected_mobile_app_ids: Vec<String>,
    pub assignments: Vec<EspGraphAssignment>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphAppRecord {
    pub app_id: String,
    pub display_name: Option<String>,
    pub tracked_on_enrollment_status: Option<bool>,
    pub status: Option<EspStatus>,
    pub intent_state: GraphSection<EspStatus>,
    pub assignments: Vec<EspGraphAssignment>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphPolicyRecord {
    pub policy_id: String,
    pub display_name: Option<String>,
    pub kind: EspGraphPolicyKind,
    pub status: Option<EspStatus>,
    pub assignments: Vec<EspGraphAssignment>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphScriptRecord {
    pub script_id: String,
    pub display_name: Option<String>,
    pub kind: EspGraphScriptKind,
    pub status: Option<EspStatus>,
    pub assignments: Vec<EspGraphAssignment>,
    pub evidence: Vec<EspEvidenceRef>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct EspGraphOverlay {
    pub request_id: String,
    pub requested_at_utc: String,
    pub device_match: GraphSection<EspGraphDeviceMatch>,
    pub autopilot_identity: GraphSection<EspGraphAutopilotIdentity>,
    pub deployment_profile: GraphSection<EspGraphDeploymentProfile>,
    pub intended_deployment_profile: GraphSection<EspGraphDeploymentProfile>,
    pub profile_assignments: GraphSection<Vec<EspGraphAssignment>>,
    pub autopilot_events: GraphSection<Vec<EspGraphAutopilotEvent>>,
    pub enrollment_configuration: GraphSection<EspGraphEnrollmentConfiguration>,
    pub apps: GraphSection<Vec<EspGraphAppRecord>>,
    pub policies: GraphSection<Vec<EspGraphPolicyRecord>>,
    pub scripts: GraphSection<Vec<EspGraphScriptRecord>>,
}