lenso-platform-admin-data 0.1.22

Schema-admin data backend for the Lenso host.
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
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
//! Generic container DTOs for schema-admin endpoints. The record shape is
//! `serde_json::Value` because the renderer is generic across arbitrary modules.

use platform_core::{StoryDisplayDescriptor, StoryDisplaySource};
use platform_module::{
    AdminSchema, AdminSurface, ConsoleContribution, ConsoleSlot, ConsoleSurface, EventSurface,
    LifecycleSurface, ModuleHttpRoute, ModuleManifestLint, ModuleSource, RuntimeSurface,
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Response for `GET /admin/data/schema`: every admin-capable module's schema.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminSchemaListResponse {
    pub modules: Vec<AdminModuleSchema>,
}

/// Response for `POST /admin/data/schema/refresh`.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminSchemaRefreshResponse {
    pub modules: Vec<AdminModuleSchema>,
}

/// Response for `GET /admin/data/modules`: every registered module's metadata,
/// including modules without admin surfaces.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleMetadataListResponse {
    pub modules: Vec<AdminModuleMetadataDto>,
    pub refreshed_at: Option<String>,
    pub refresh_error: Option<String>,
    pub refresh_history: Vec<AdminModuleRefreshRecordDto>,
}

/// Response for `GET /admin/data/available-modules`: a read-only list of
/// catalog entries that can be installed from their manifest URL.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleRegistrySnapshotResponse {
    pub version: u8,
    pub status: AdminModuleRegistrySnapshotStatus,
    pub catalog: AdminModuleRegistrySnapshotCatalogDto,
    pub issues: Vec<AdminModuleRegistrySnapshotIssueDto>,
    pub modules: Vec<AdminModuleRegistrySnapshotModuleDto>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleRegistrySnapshotStatus {
    Passed,
    Failed,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleRegistrySnapshotCatalogDto {
    pub modules: usize,
    pub registry_file: String,
    pub version: u8,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleRegistrySnapshotIssueDto {
    pub group: String,
    pub message: String,
    pub fix: String,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleRegistrySnapshotModuleDto {
    pub name: String,
    pub source: ModuleSource,
    pub catalog_version: String,
    pub manifest_reference: String,
    #[serde(default, rename = "providedBy")]
    pub provided_by: Option<String>,
    #[serde(default, rename = "serviceManifest")]
    pub service_manifest: Option<String>,
    #[serde(default, rename = "moduleRelease")]
    pub module_release: Option<AdminModuleReleaseDto>,
    pub summary: Option<String>,
    pub base_url: Option<String>,
    pub capabilities: Vec<String>,
    pub console_package_hints: usize,
    pub compatibility: Option<AdminModuleCompatibilityDto>,
    pub host_compatibility: AdminModuleHostCompatibilityDto,
    pub archived_at: Option<String>,
    pub archive_reason: Option<String>,
    pub manifest_name: Option<String>,
    pub manifest_status: AdminModuleRegistrySnapshotManifestStatus,
    pub manifest_version: Option<String>,
    pub install_state: AdminModuleInstallStateDto,
    pub status: AdminModuleRegistrySnapshotModuleStatus,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleInstallStateDto {
    pub module_registered: bool,
    pub linked_source: Option<AdminModuleLinkedSourceInstallStateDto>,
    pub remote_source: Option<AdminModuleRemoteSourceInstallStateDto>,
    pub console_plan: AdminModuleConsolePackagePlanStateDto,
}

#[derive(Debug, Clone, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleReleaseDto {
    pub manifest_reference: String,
    pub name: Option<String>,
    pub version: Option<String>,
    pub source: Option<String>,
    pub provider_name: Option<String>,
    pub service_package: Option<String>,
    pub service_manifest: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleLifecycleResponse {
    pub version: u8,
    pub status: AdminServiceModuleLifecycleStatus,
    pub modules: Vec<AdminServiceModuleLifecycleModuleDto>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemResponse {
    pub version: u8,
    pub status: AdminServiceSystemStatus,
    pub system_file: String,
    pub name: Option<String>,
    pub environments: Vec<String>,
    pub services: Vec<AdminServiceSystemServiceDto>,
    pub modules: Vec<AdminServiceSystemModuleDto>,
    pub dependencies: Vec<AdminServiceSystemDependencyDto>,
    pub issues: Vec<AdminServiceSystemIssueDto>,
    pub protocol_version: Option<String>,
    pub semantic_kind: Option<String>,
    pub nodes: Vec<AdminServiceSystemNodeDto>,
    pub relationships: Vec<AdminServiceSystemRelationshipDto>,
    pub compatibility_results: Vec<AdminContractCompatibilityResultDto>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemNodeDto {
    pub id: String,
    pub kind: String,
    pub owner: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemRelationshipDto {
    pub kind: String,
    pub from: String,
    pub to: String,
    pub contract_id: Option<String>,
    pub contract_version: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminContractCompatibilityResultDto {
    pub category: String,
    pub contract_kind: String,
    pub contract_id: String,
    pub changed_version: String,
    pub affected_references: Vec<String>,
    pub reasons: Vec<AdminContractCompatibilityReasonDto>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminContractCompatibilityReasonDto {
    pub code: String,
    pub path: String,
    pub message: String,
    pub next_action: String,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceSystemStatus {
    Ready,
    NeedsAttention,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemServiceDto {
    pub name: String,
    pub target: String,
    pub modules: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemModuleDto {
    pub name: String,
    pub owner: String,
    pub capabilities: Vec<String>,
    pub dependencies: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemDependencyDto {
    pub from: String,
    pub capability: String,
    pub state: String,
    pub to: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemIssueDto {
    pub code: String,
    pub message: String,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemDriftResponse {
    pub version: u8,
    pub status: AdminServiceSystemDriftStatus,
    pub system_file: String,
    pub graph_issues: Vec<AdminServiceSystemIssueDto>,
    pub drifts: Vec<AdminServiceSystemDriftDto>,
    pub commands: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceSystemDriftStatus {
    Ready,
    Drifted,
    NeedsAttention,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemDriftDto {
    pub code: String,
    pub severity: String,
    pub resource: String,
    pub name: String,
    pub message: String,
    pub command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemReleaseTrainResponse {
    pub version: u8,
    pub status: AdminServiceSystemReleaseTrainStatus,
    pub releases: Vec<AdminServiceSystemReleaseRecordDto>,
    pub commands: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceSystemReleaseTrainStatus {
    Ready,
    NeedsAttention,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemReleaseRecordDto {
    pub id: String,
    pub kind: String,
    pub system_name: String,
    pub environment: String,
    pub status: String,
    pub policy_risk: String,
    pub applied_at_unix_ms: Option<u64>,
    pub services: usize,
    pub modules: usize,
    pub rollback_available: bool,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemRunbooksResponse {
    pub version: u8,
    pub status: AdminServiceSystemRunbooksStatus,
    pub runbooks: Vec<AdminServiceSystemRunbookDto>,
    pub commands: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceSystemRunbooksStatus {
    Ready,
    NeedsAttention,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceSystemRunbookDto {
    pub id: String,
    pub release_id: String,
    pub system_name: String,
    pub environment: String,
    pub status: String,
    pub active: bool,
    pub recorded_at_unix_ms: Option<u64>,
    pub steps: usize,
    pub current_step: Option<String>,
}

/// Response for `GET /admin/data/launchpad`: generated first-run app state.
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadResponse {
    pub version: u8,
    pub status: AdminLaunchpadStatus,
    pub launchpad_file: String,
    pub project_name: Option<String>,
    pub blueprint: Option<String>,
    pub summary: Option<String>,
    pub services: Vec<AdminLaunchpadServiceDto>,
    pub modules: Vec<AdminLaunchpadModuleDto>,
    pub checklist: Vec<AdminLaunchpadChecklistItemDto>,
    pub addons: Vec<AdminLaunchpadAddonDto>,
    pub supported_addons: Vec<String>,
    pub commands: Vec<String>,
    pub next_command: Option<String>,
    pub issues: Vec<AdminLaunchpadIssueDto>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminLaunchpadStatus {
    Ready,
    NeedsAttention,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadServiceDto {
    pub name: String,
    pub role: Option<String>,
    pub language: Option<String>,
    pub cwd: Option<String>,
    pub command: Option<String>,
    pub ready_url: Option<String>,
    pub modules: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadModuleDto {
    pub name: String,
    pub owner_service: Option<String>,
    pub capability: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadChecklistItemDto {
    pub id: String,
    pub label: String,
    pub status: String,
    pub next_command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadIssueDto {
    pub code: String,
    pub message: String,
    pub command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadAddonDto {
    pub name: String,
    pub label: String,
    pub status: String,
    pub services: Vec<String>,
    pub modules: Vec<String>,
}

/// Response for `GET /admin/data/launchpad/doctor`: latest local developer doctor snapshot.
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadDoctorResponse {
    pub version: u8,
    pub status: AdminLaunchpadDoctorStatus,
    pub doctor_file: String,
    pub checked_at_unix_ms: Option<u64>,
    pub live: bool,
    pub checks: Vec<AdminLaunchpadDoctorCheckDto>,
    pub next_command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminLaunchpadDoctorStatus {
    Ready,
    NeedsAttention,
    Failed,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadDoctorCheckDto {
    pub id: String,
    pub label: String,
    pub status: String,
    pub message: String,
    pub command: Option<String>,
}

/// Response for `GET /admin/data/launchpad/proof`: latest generated App Proof snapshot.
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadProofResponse {
    pub version: u8,
    pub status: AdminLaunchpadProofStatus,
    pub proof_file: String,
    pub checked_at_unix_ms: Option<u64>,
    pub project_name: Option<String>,
    pub blueprint: Option<String>,
    pub addons: Vec<String>,
    pub checks: Vec<AdminLaunchpadProofCheckDto>,
    pub drifts: Vec<AdminLaunchpadProofDriftDto>,
    pub next_command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminLaunchpadProofStatus {
    Ready,
    Drifted,
    NeedsAttention,
    Failed,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadProofCheckDto {
    pub id: String,
    pub label: String,
    pub status: String,
    pub message: String,
    pub command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadProofDriftDto {
    pub resource: String,
    pub name: String,
    pub message: String,
    pub command: Option<String>,
}

/// Response for `GET /admin/data/launchpad/change-plan`: latest generated app change plan.
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadChangePlanResponse {
    pub version: u8,
    pub status: AdminLaunchpadChangePlanStatus,
    pub plan_file: String,
    pub generated_at_unix_ms: Option<u64>,
    pub project_name: Option<String>,
    pub blueprint: Option<String>,
    pub addons: Vec<String>,
    pub proof_status: Option<String>,
    pub changes: Vec<AdminLaunchpadChangePlanItemDto>,
    pub blocked: Vec<AdminLaunchpadChangePlanItemDto>,
    pub next_command: Option<String>,
    pub composition: Option<AdminLaunchpadCompositionDto>,
    pub issues: Vec<AdminLaunchpadIssueDto>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminLaunchpadChangePlanStatus {
    Ready,
    Changes,
    Blocked,
    NeedsSetup,
    Failed,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadChangePlanItemDto {
    pub id: String,
    pub kind: String,
    pub name: String,
    pub action: String,
    pub safe: bool,
    pub message: String,
    pub command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadCompositionDto {
    pub protocol: String,
    pub intent: Option<String>,
    pub requested_addons: Vec<String>,
    pub applied_addons: Vec<String>,
    pub pending_addons: Vec<String>,
    pub requested_packs: Vec<String>,
    pub applied_packs: Vec<String>,
    pub pending_packs: Vec<String>,
    pub capability_packs: Vec<AdminLaunchpadCapabilityPackDto>,
    pub pack_fit: Vec<AdminLaunchpadPackFitDto>,
    pub service_actions: Vec<AdminLaunchpadCompositionActionDto>,
    pub agent_actions: Vec<AdminLaunchpadCompositionActionDto>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadCapabilityPackDto {
    pub name: String,
    pub path: String,
    pub status: String,
    pub modules: Vec<String>,
    pub services: Vec<String>,
    pub next_command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadPackFitDto {
    pub name: String,
    pub path: String,
    pub status: String,
    pub issues: Vec<String>,
    pub command: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminLaunchpadCompositionActionDto {
    pub id: String,
    pub kind: String,
    pub label: String,
    pub command: Option<String>,
    pub status: String,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceModuleLifecycleStatus {
    Ready,
    NeedsAttention,
    Empty,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleLifecycleModuleDto {
    pub module_name: String,
    pub provider_name: Option<String>,
    pub status: AdminServiceModuleLifecycleModuleStatus,
    pub installed: bool,
    pub configured: bool,
    pub loaded: bool,
    pub restart_pending: bool,
    pub base_url: Option<String>,
    pub manifest_url: Option<String>,
    pub manifest_status: AdminServiceModuleManifestStatus,
    pub status_url: Option<String>,
    pub service_status: AdminServiceModuleServiceStatusDto,
    pub health_history: Vec<AdminServiceModuleHealthCheckDto>,
    pub compatibility: AdminServiceModuleCompatibilityDto,
    pub config: AdminServiceModuleConfigDto,
    pub deployment: Option<AdminServiceModuleDeploymentDto>,
    pub environments: Vec<AdminServiceEnvironmentDto>,
    pub deployments: Vec<AdminServiceDeploymentObservationDto>,
    pub deployment_history: Vec<AdminServiceDeploymentObservationDto>,
    pub deployment_drift: Option<String>,
    pub deployment_next_action: Option<String>,
    pub services: Vec<AdminServiceModuleLifecycleServiceDto>,
    pub operations: Vec<AdminServiceOperationDto>,
    pub module_release: Option<AdminModuleReleaseDto>,
    pub latest_release: Option<AdminServiceReleaseRecordDto>,
    pub release_history: Vec<AdminServiceReleaseRecordDto>,
    pub fixes: Vec<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceReleaseRecordDto {
    pub id: Option<String>,
    pub service_name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub environment: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target: Option<String>,
    pub applied_at_unix_ms: Option<u64>,
    pub risk: String,
    pub current_version: Option<String>,
    pub candidate_version: Option<String>,
    pub current_manifest_reference: Option<String>,
    pub candidate_manifest_reference: Option<String>,
    pub candidate_package_reference: Option<String>,
    pub rollback_target: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceEnvironmentDto {
    pub name: String,
    pub service_name: String,
    pub target: String,
    pub namespace: Option<String>,
    pub kube_context: Option<String>,
    pub image: Option<String>,
    pub public_base_url: Option<String>,
    pub manifest_reference: Option<String>,
    pub release_track: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceDeploymentObservationDto {
    pub service_name: String,
    pub environment: String,
    pub target: String,
    pub observed_at_unix_ms: Option<u64>,
    pub state: String,
    pub drift: String,
    pub operator: Option<AdminServiceDeploymentOperatorObservationDto>,
    pub cluster: Option<AdminKubernetesDeploymentObservationDto>,
    pub host: Option<AdminServiceDeploymentHostObservationDto>,
    pub checks: Vec<AdminServiceDeploymentCheckDto>,
    pub next_action: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceDeploymentOperatorObservationDto {
    pub resource: Option<String>,
    pub namespace: Option<String>,
    pub observed_generation: Option<u64>,
    pub conditions: Vec<AdminServiceDeploymentOperatorConditionDto>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceDeploymentOperatorConditionDto {
    #[serde(rename = "type")]
    pub type_: Option<String>,
    pub status: Option<String>,
    pub reason: Option<String>,
    pub message: Option<String>,
    pub last_transition_time: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminKubernetesDeploymentObservationDto {
    pub namespace: Option<String>,
    pub deployment: Option<String>,
    pub ready_replicas: Option<u32>,
    pub desired_replicas: Option<u32>,
    pub available_replicas: Option<u32>,
    pub image: Option<String>,
    pub release_id: Option<String>,
    pub manifest_reference: Option<String>,
    pub service_endpoint: Option<String>,
    pub ingress_host: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceDeploymentHostObservationDto {
    pub release_id: Option<String>,
    pub candidate_version: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceDeploymentCheckDto {
    pub name: String,
    pub status: String,
    pub detail: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceOperationKindDto {
    HttpRoute,
    RuntimeFunction,
    EventHandler,
    AdminAction,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceOperationLinksDto {
    pub remote_calls: Option<String>,
    pub runtime: Option<String>,
    pub story: String,
    pub technical_operations: String,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceOperationDto {
    pub operation_id: String,
    pub provider_name: Option<String>,
    pub module_name: String,
    pub kind: AdminServiceOperationKindDto,
    pub name: String,
    pub method: Option<String>,
    pub path: Option<String>,
    pub capability: Option<String>,
    pub summary: Option<String>,
    pub safe_probe: bool,
    pub links: AdminServiceOperationLinksDto,
    pub next_action: String,
}

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleHealthCheckDto {
    pub module_name: String,
    pub checked_at_unix_ms: u64,
    pub status_url: String,
    pub state: String,
    pub error: Option<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceModuleLifecycleModuleStatus {
    Ready,
    MissingConfig,
    RestartPending,
    ConfiguredNotLoaded,
    ManifestUnreachable,
    ServiceNotReady,
    StaleState,
    NotConfigured,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleConfigDto {
    pub env_file: String,
    pub required_env: Vec<String>,
    pub configured_env: Vec<String>,
    pub missing_env: Vec<String>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceModuleManifestStatus {
    Reachable,
    Unreachable,
    Skipped,
    NotConfigured,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleLifecycleServiceDto {
    pub name: String,
    pub ready_url: String,
    pub ready: bool,
    pub auto_start: bool,
    pub lock_file: Option<String>,
    pub pid_file: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleServiceStatusDto {
    pub checked: bool,
    pub state: AdminServiceModuleServiceStatusState,
    pub error: Option<String>,
    pub checks: Vec<AdminServiceModuleServiceStatusCheckDto>,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceModuleServiceStatusState {
    Ready,
    Degraded,
    Starting,
    Unreachable,
    Unknown,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleServiceStatusCheckDto {
    pub name: String,
    pub status: String,
    pub detail: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleCompatibilityDto {
    pub state: AdminServiceModuleCompatibilityState,
    pub declared: Option<AdminModuleCompatibilityDto>,
    pub host: AdminModuleHostCompatibilityDto,
    pub issue: Option<String>,
    pub fix: Option<String>,
    pub override_allowed: bool,
}

#[derive(Debug, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AdminServiceModuleCompatibilityState {
    Compatible,
    Blocked,
    Unknown,
}

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminServiceModuleDeploymentDto {
    pub target: Option<String>,
    #[serde(default)]
    pub commands: Vec<String>,
    pub compose_service: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleLinkedSourceInstallStateDto {
    pub env_file: String,
    pub configured: bool,
    pub desired_enabled: Option<bool>,
    pub running_enabled: bool,
    pub restart_pending: bool,
    pub restart_reason: Option<String>,
    pub error: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleRemoteSourceInstallStateDto {
    pub env_file: String,
    pub configured: bool,
    pub desired_base_url: Option<String>,
    pub running_base_url: Option<String>,
    pub restart_pending: bool,
    pub restart_reason: Option<String>,
    pub error: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleConsolePackagePlanStateDto {
    pub plan_file: String,
    pub exists: bool,
    pub readable: bool,
    pub error: Option<String>,
    pub module_entry_present: bool,
    pub package_count: usize,
    pub restart_required: Option<bool>,
    pub packages: Vec<AdminModuleConsolePackagePlanPackageDto>,
}

/// Response for visually installing an available service or linked module from
/// the curated catalog.
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleInstallResponse {
    pub module_name: String,
    pub manifest_reference: String,
    pub module_release: Option<AdminModuleReleaseDto>,
    pub linked_source: Option<AdminModuleLinkedSourceInstallStateDto>,
    pub remote_source: Option<AdminModuleRemoteSourceInstallStateDto>,
    pub console_plan: AdminModuleConsolePackagePlanStateDto,
    pub restart_required: bool,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleConsolePackagePlanPackageDto {
    pub key: Option<String>,
    pub package_name: String,
    pub export_name: String,
    pub command: Option<String>,
    pub route: Option<String>,
    pub status: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleCompatibilityDto {
    #[serde(alias = "console_package_api")]
    pub console_package_api: Option<String>,
    pub lenso: Option<AdminModuleLensoCompatibilityDto>,
    #[serde(alias = "remote_protocol_version")]
    pub remote_protocol_version: Option<String>,
    #[serde(default, alias = "required_host_features")]
    pub required_host_features: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleLensoCompatibilityDto {
    #[serde(alias = "min_version")]
    pub min_version: Option<String>,
    #[serde(alias = "max_version")]
    pub max_version: Option<String>,
}

#[derive(Clone, Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct AdminModuleHostCompatibilityDto {
    pub console_package_api: String,
    pub lenso_version: String,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleRegistrySnapshotManifestStatus {
    Ok,
    Invalid,
    Unreadable,
    Archived,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleRegistrySnapshotModuleStatus {
    Ready,
    NeedsAttention,
    Archived,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleRefreshRecordDto {
    pub id: String,
    pub status: AdminModuleRefreshStatusDto,
    pub started_at: String,
    pub completed_at: String,
    pub duration_ms: u64,
    pub module_count: usize,
    pub error: Option<String>,
    pub module_results: Vec<AdminModuleRefreshModuleResultDto>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleRefreshStatusDto {
    Success,
    Error,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleRefreshModuleResultDto {
    pub module_name: String,
    pub source: ModuleSource,
    pub status: AdminModuleRefreshModuleStatusDto,
    pub duration_ms: Option<u64>,
    pub endpoint: Option<String>,
    pub error: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleRefreshModuleStatusDto {
    Loaded,
    Error,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleMetadataDto {
    pub module_name: String,
    pub source: ModuleSource,
    pub status: AdminModuleStatus,
    pub error: Option<String>,
    pub source_diagnostics: Option<AdminModuleSourceDiagnosticsDto>,
    pub http_routes: Vec<ModuleHttpRoute>,
    pub runtime: Option<RuntimeSurface>,
    pub events: Option<EventSurface>,
    pub lifecycle: Option<LifecycleSurface>,
    pub console: Vec<ConsoleSurface>,
    pub console_slots: Vec<ConsoleSlot>,
    pub console_contributions: Vec<ConsoleContribution>,
    pub governance: AdminModuleGovernanceDto,
    pub manifest_lints: Vec<ModuleManifestLint>,
    pub story_display: Vec<StoryDisplayDescriptorDto>,
    pub capabilities: Vec<String>,
    pub dependencies: Vec<String>,
    pub admin: Option<AdminSurface>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum AdminModuleSourceDiagnosticsDto {
    Remote(AdminRemoteModuleDiagnosticsDto),
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminRemoteModuleDiagnosticsDto {
    pub transport: String,
    pub base_url: String,
    pub manifest_url: String,
    pub timeout_ms: u64,
    pub auth_configured: bool,
    pub load_duration_ms: Option<u64>,
    pub last_checked_at: Option<String>,
    pub last_load_error: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleGovernanceDto {
    pub activation_state: AdminModuleActivationState,
    pub activation_reasons: Vec<String>,
    pub capability_summary: AdminCapabilitySummaryDto,
    pub capability_issues: Vec<AdminCapabilityIssueDto>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleActivationState {
    Active,
    NeedsAttention,
    Blocked,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminCapabilitySummaryDto {
    pub declared_count: usize,
    pub referenced_count: usize,
    pub missing_count: usize,
    pub unused_count: usize,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminCapabilityIssueDto {
    pub capability: String,
    pub subject: String,
    pub message: String,
    pub suggestion: String,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct StoryDisplayDescriptorDto {
    pub source: StoryDisplaySourceDto,
    pub display_name: String,
    pub story_title: Option<String>,
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum StoryDisplaySourceDto {
    ExecutionName { name: String },
    HttpRequest { method: String, path: String },
}

impl From<StoryDisplayDescriptor> for StoryDisplayDescriptorDto {
    fn from(descriptor: StoryDisplayDescriptor) -> Self {
        Self {
            source: descriptor.source.into(),
            display_name: descriptor.display_name,
            story_title: descriptor.story_title,
        }
    }
}

impl From<StoryDisplaySource> for StoryDisplaySourceDto {
    fn from(source: StoryDisplaySource) -> Self {
        match source {
            StoryDisplaySource::ExecutionName { name } => Self::ExecutionName { name },
            StoryDisplaySource::HttpRequest { method, path } => Self::HttpRequest { method, path },
        }
    }
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminModuleSchema {
    pub module_name: String,
    pub source: ModuleSource,
    pub status: AdminModuleStatus,
    pub error: Option<String>,
    pub schema: AdminSchema,
}

#[derive(Debug, Clone, Copy, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdminModuleStatus {
    Loaded,
    Error,
}

/// Response for `GET /admin/data/{module}/{entity}`: a page of records.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminDataListResponse {
    /// Each record is an arbitrary JSON object whose keys match the entity schema.
    pub data: Vec<serde_json::Value>,
    pub page: AdminDataPageInfo,
}

/// Pagination info. `next_cursor` is an opaque token (not a timestamp like
/// platform-admin's PageInfo) so it makes no assumption about entity shape.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminDataPageInfo {
    pub limit: i64,
    pub next_cursor: Option<String>,
}

/// Response for `GET /admin/data/{module}/{entity}/{id}`.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminDataDetailResponse {
    pub data: serde_json::Value,
}

/// Response for `GET /admin/data/{module}/queries/{query}`.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminQueryResponse {
    pub data: serde_json::Value,
}

/// Request body for `POST /admin/data/{module}/actions/{action}`.
#[derive(Debug, Clone, Deserialize, ToSchema)]
pub struct AdminActionInvokeRequest {
    #[serde(default)]
    pub input: serde_json::Value,
    #[serde(default)]
    pub confirmation_phrase: Option<String>,
}

/// Response for `POST /admin/data/{module}/actions/{action}`.
#[derive(Debug, Serialize, ToSchema)]
pub struct AdminActionInvokeResponse {
    pub data: serde_json::Value,
    pub invocation: AdminActionInvocationDto,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct AdminActionInvocationDto {
    pub request_id: String,
    pub correlation_id: String,
    pub story_node_id: String,
}