dioxus-cli 0.7.6

CLI for building fullstack web, desktop, and mobile apps with a single codebase.
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
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
//! Unified manifest configuration for cross-platform app packaging.
//!
//! This module provides configuration structs for permissions and platform-specific
//! manifest customization. Permissions declared here are automatically mapped to
//! platform-specific identifiers (AndroidManifest.xml, Info.plist, etc.)
//!
//! ## JSON Schema Generation
//!
//! Generate a JSON schema for IDE autocomplete:
//! ```bash
//! dx config --schema > dioxus-schema.json
//! ```

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;

// ============================================================================
// Unified Permissions
// ============================================================================

/// Unified permission configuration that maps to platform-specific identifiers.
///
/// Example:
/// ```toml
/// [permissions]
/// location = { precision = "fine", description = "Track your runs" }
/// camera = { description = "Take photos for your profile" }
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct PermissionsConfig {
    /// Location permission with precision level.
    /// Maps to ACCESS_FINE_LOCATION/ACCESS_COARSE_LOCATION on Android,
    /// NSLocationWhenInUseUsageDescription on iOS/macOS.
    #[serde(default)]
    pub location: Option<LocationPermission>,

    /// Camera access permission.
    #[serde(default)]
    pub camera: Option<SimplePermission>,

    /// Microphone access permission.
    #[serde(default)]
    pub microphone: Option<SimplePermission>,

    /// Push notifications permission.
    #[serde(default)]
    pub notifications: Option<SimplePermission>,

    /// Photo library access.
    #[serde(default)]
    pub photos: Option<StoragePermission>,

    /// Bluetooth connectivity.
    #[serde(default)]
    pub bluetooth: Option<SimplePermission>,

    /// Background location updates.
    #[serde(default, rename = "background-location")]
    pub background_location: Option<SimplePermission>,

    /// Contacts access.
    #[serde(default)]
    pub contacts: Option<StoragePermission>,

    /// Calendar access.
    #[serde(default)]
    pub calendar: Option<StoragePermission>,

    /// Biometric authentication (Face ID, fingerprint).
    #[serde(default)]
    pub biometrics: Option<SimplePermission>,

    /// NFC access.
    #[serde(default)]
    pub nfc: Option<SimplePermission>,

    /// Motion and fitness data.
    #[serde(default)]
    pub motion: Option<SimplePermission>,

    /// Health data access.
    #[serde(default)]
    pub health: Option<StoragePermission>,

    /// Speech recognition.
    #[serde(default)]
    pub speech: Option<SimplePermission>,

    /// Media library access.
    #[serde(default, rename = "media-library")]
    pub media_library: Option<SimplePermission>,

    /// Siri integration (iOS only).
    #[serde(default)]
    pub siri: Option<SimplePermission>,

    /// HomeKit integration (iOS only).
    #[serde(default)]
    pub homekit: Option<SimplePermission>,

    /// Local network access.
    #[serde(default, rename = "local-network")]
    pub local_network: Option<SimplePermission>,

    /// Nearby Wi-Fi devices (Android).
    #[serde(default, rename = "nearby-wifi")]
    pub nearby_wifi: Option<SimplePermission>,
}

/// Simple permission with just a description.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct SimplePermission {
    /// User-facing description shown in permission dialogs.
    pub description: String,
}

// ============================================================================
// Unified Deep Linking
// ============================================================================

/// Unified deep linking configuration.
///
/// This provides a cross-platform interface for URL schemes and universal/app links.
/// Platform-specific overrides can be configured in `[ios]` and `[android]` sections.
///
/// Example:
/// ```toml
/// [deep_links]
/// schemes = ["myapp", "com.example.myapp"]
/// hosts = ["example.com", "*.example.com"]
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct DeepLinkConfig {
    /// Custom URL schemes (e.g., "myapp" for myapp://path).
    /// Maps to CFBundleURLSchemes on iOS/macOS and intent-filter on Android.
    #[serde(default)]
    pub schemes: Vec<String>,

    /// Universal link / App link hosts (e.g., "example.com").
    /// Maps to Associated Domains on iOS and App Links on Android.
    /// Supports wildcards like "*.example.com".
    #[serde(default)]
    pub hosts: Vec<String>,

    /// Path patterns for universal/app links (e.g., "/app/*", "/share/*").
    /// If empty, all paths are matched.
    #[serde(default)]
    pub paths: Vec<String>,
}

// ============================================================================
// Unified Background Modes
// ============================================================================

/// Unified background execution configuration.
///
/// This provides a cross-platform interface for background capabilities.
/// Platform-specific overrides can be configured in `[ios]` and `[android]` sections.
///
/// Example:
/// ```toml
/// [background]
/// location = true
/// audio = true
/// fetch = true
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct BackgroundConfig {
    /// Background location updates.
    /// iOS: UIBackgroundModes "location"
    /// Android: ACCESS_BACKGROUND_LOCATION permission
    #[serde(default)]
    pub location: bool,

    /// Background audio playback.
    /// iOS: UIBackgroundModes "audio"
    /// Android: FOREGROUND_SERVICE_MEDIA_PLAYBACK
    #[serde(default)]
    pub audio: bool,

    /// Background data fetch.
    /// iOS: UIBackgroundModes "fetch"
    /// Android: WorkManager or foreground service
    #[serde(default)]
    pub fetch: bool,

    /// Remote push notifications.
    /// iOS: UIBackgroundModes "remote-notification"
    /// Android: Firebase Cloud Messaging
    #[serde(default, rename = "remote-notifications")]
    pub remote_notifications: bool,

    /// VoIP calls.
    /// iOS: UIBackgroundModes "voip"
    /// Android: FOREGROUND_SERVICE_PHONE_CALL
    #[serde(default)]
    pub voip: bool,

    /// Bluetooth LE accessories.
    /// iOS: UIBackgroundModes "bluetooth-central" and "bluetooth-peripheral"
    /// Android: FOREGROUND_SERVICE_CONNECTED_DEVICE
    #[serde(default)]
    pub bluetooth: bool,

    /// External accessory communication.
    /// iOS: UIBackgroundModes "external-accessory"
    #[serde(default, rename = "external-accessory")]
    pub external_accessory: bool,

    /// Background processing tasks.
    /// iOS: UIBackgroundModes "processing"
    /// Android: WorkManager
    #[serde(default)]
    pub processing: bool,
}

/// Location permission with precision control.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct LocationPermission {
    /// Precision level: "fine" (GPS) or "coarse" (network-based).
    #[serde(default)]
    pub precision: LocationPrecision,

    /// User-facing description shown in permission dialogs.
    pub description: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, JsonSchema)]
pub enum LocationPrecision {
    #[default]
    #[serde(rename = "fine")]
    Fine,
    #[serde(rename = "coarse")]
    Coarse,
}

/// Storage permission with access level control.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct StoragePermission {
    /// Access level: "read", "write", or "read-write".
    #[serde(default)]
    pub access: StorageAccess,

    /// User-facing description shown in permission dialogs.
    pub description: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, JsonSchema)]
pub enum StorageAccess {
    #[serde(rename = "read")]
    Read,
    #[serde(rename = "write")]
    Write,
    #[default]
    #[serde(rename = "read-write")]
    ReadWrite,
}

/// Raw platform permission entry.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct RawPermission {
    pub description: String,
}

// ============================================================================
// iOS Configuration
// ============================================================================

/// iOS-specific configuration.
///
/// Example:
/// ```toml
/// [ios]
/// deployment_target = "15.0"
/// identifier = "com.example.myapp.ios"  # Override bundle.identifier for iOS
///
/// [ios.entitlements]
/// app-groups = ["group.com.example.app"]
///
/// [ios.plist]
/// UIBackgroundModes = ["location", "fetch"]
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct IosConfig {
    // === Bundle settings (override [bundle] section) ===
    /// The app's identifier (e.g., "com.example.myapp").
    /// Overrides `bundle.identifier` for iOS builds.
    #[serde(default)]
    pub identifier: Option<String>,

    /// The app's publisher.
    /// Overrides `bundle.publisher` for iOS builds.
    #[serde(default)]
    pub publisher: Option<String>,

    /// Icons for the app.
    /// Overrides `bundle.icon` for iOS builds.
    #[serde(default)]
    pub icon: Option<Vec<String>>,

    /// Additional resources to bundle.
    /// Overrides `bundle.resources` for iOS builds.
    #[serde(default)]
    pub resources: Option<Vec<String>>,

    /// Copyright notice.
    /// Overrides `bundle.copyright` for iOS builds.
    #[serde(default)]
    pub copyright: Option<String>,

    /// App category.
    /// Overrides `bundle.category` for iOS builds.
    #[serde(default)]
    pub category: Option<String>,

    /// Short description.
    /// Overrides `bundle.short_description` for iOS builds.
    #[serde(default)]
    pub short_description: Option<String>,

    /// Long description.
    /// Overrides `bundle.long_description` for iOS builds.
    #[serde(default)]
    pub long_description: Option<String>,

    // === iOS-specific settings ===
    /// Minimum iOS deployment target (e.g., "15.0").
    #[serde(default)]
    pub deployment_target: Option<String>,

    /// Path to custom Info.plist to merge with generated.
    #[serde(default)]
    pub info_plist: Option<PathBuf>,

    /// iOS entitlements configuration.
    #[serde(default)]
    pub entitlements: IosEntitlements,

    /// Additional Info.plist keys to merge.
    #[serde(default)]
    pub plist: HashMap<String, serde_json::Value>,

    /// Raw XML injection points.
    #[serde(default)]
    pub raw: IosRawConfig,

    // === Platform-specific overrides (extend unified config) ===
    /// Additional URL schemes beyond unified `[deep_links]`.schemes.
    /// These are merged with the unified schemes.
    #[serde(default)]
    pub url_schemes: Vec<String>,

    /// Additional background modes beyond unified `[background]`.
    /// Valid values: "audio", "location", "voip", "fetch", "remote-notification",
    /// "newsstand-content", "external-accessory", "bluetooth-central",
    /// "bluetooth-peripheral", "processing"
    #[serde(default)]
    pub background_modes: Vec<String>,

    /// Document types the app can open.
    #[serde(default)]
    pub document_types: Vec<IosDocumentType>,

    /// Exported type identifiers (custom UTIs).
    #[serde(default)]
    pub exported_type_identifiers: Vec<IosTypeIdentifier>,

    /// Imported type identifiers.
    #[serde(default)]
    pub imported_type_identifiers: Vec<IosTypeIdentifier>,

    /// Widget extensions to compile and bundle.
    /// Each entry defines a Swift-based widget extension (.appex) that will be
    /// compiled and installed into the app's PlugIns folder.
    #[serde(default)]
    pub widget_extensions: Vec<WidgetExtensionConfig>,
}

/// Configuration for an iOS Widget Extension.
///
/// Widget extensions are compiled as Swift executables and bundled as .appex
/// bundles in the app's PlugIns folder.
///
/// Example in Dioxus.toml:
/// ```toml
/// [[ios.widget_extensions]]
/// source = "src/ios/widget"
/// display_name = "Location Widget"
/// bundle_id_suffix = "location-widget"
/// deployment_target = "16.2"
/// module_name = "GeolocationPlugin"
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct WidgetExtensionConfig {
    /// Path to the Swift package source directory (relative to project root).
    pub source: String,

    /// Display name for the widget (shown in system UI).
    pub display_name: String,

    /// Bundle ID suffix appended to the app's bundle identifier.
    /// For example, if the app is "com.example.app" and suffix is "location-widget",
    /// the widget bundle ID will be "com.example.app.location-widget".
    pub bundle_id_suffix: String,

    /// Minimum deployment target (e.g., "16.2").
    /// Defaults to the app's iOS deployment target if not specified.
    #[serde(default)]
    pub deployment_target: Option<String>,

    /// Swift module name for the widget.
    /// This MUST match the module name used by the main app's Swift plugin
    /// for ActivityKit type matching to work.
    pub module_name: String,
}

/// iOS document type declaration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct IosDocumentType {
    /// Document type name.
    pub name: String,

    /// File extensions (e.g., ["txt", "md"]).
    #[serde(default)]
    pub extensions: Vec<String>,

    /// MIME types.
    #[serde(default)]
    pub mime_types: Vec<String>,

    /// UTI types.
    #[serde(default)]
    pub types: Vec<String>,

    /// Icon file name.
    #[serde(default)]
    pub icon: Option<String>,

    /// Role: "Editor", "Viewer", "Shell", or "None".
    #[serde(default)]
    pub role: Option<String>,
}

/// iOS Uniform Type Identifier declaration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct IosTypeIdentifier {
    /// UTI identifier (e.g., "com.example.myformat").
    pub identifier: String,

    /// Human-readable description.
    #[serde(default)]
    pub description: Option<String>,

    /// Conforms to these UTIs.
    #[serde(default)]
    pub conforms_to: Vec<String>,

    /// File extensions.
    #[serde(default)]
    pub extensions: Vec<String>,

    /// MIME types.
    #[serde(default)]
    pub mime_types: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct IosEntitlements {
    /// App groups for shared data.
    #[serde(default, rename = "app-groups")]
    pub app_groups: Vec<String>,

    /// Push notification environment: "development" or "production".
    #[serde(default, rename = "aps-environment")]
    pub aps_environment: Option<String>,

    /// Associated domains for universal links.
    #[serde(default, rename = "associated-domains")]
    pub associated_domains: Vec<String>,

    /// Enable iCloud container support.
    #[serde(default)]
    pub icloud: bool,

    /// Keychain access groups.
    #[serde(default, rename = "keychain-access-groups")]
    pub keychain_access_groups: Vec<String>,

    /// Enable Apple Pay.
    #[serde(default, rename = "apple-pay")]
    pub apple_pay: bool,

    /// Enable HealthKit.
    #[serde(default)]
    pub healthkit: bool,

    /// Enable HomeKit.
    #[serde(default)]
    pub homekit: bool,

    /// Additional entitlements.
    #[serde(flatten)]
    pub additional: HashMap<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct IosRawConfig {
    /// Raw XML to inject into Info.plist.
    #[serde(default)]
    pub info_plist: Option<String>,

    /// Raw XML to inject into entitlements.plist.
    #[serde(default)]
    pub entitlements: Option<String>,
}

// ============================================================================
// Android Configuration
// ============================================================================

/// Android-specific configuration.
///
/// Example:
/// ```toml
/// [android]
/// min_sdk = 24
/// target_sdk = 34
/// identifier = "com.example.myapp.android"  # Override bundle.identifier for Android
/// features = ["android.hardware.location.gps"]
///
/// # Android signing configuration (previously in [bundle.android])
/// [android.signing]
/// jks_file = "keystore.jks"
/// jks_password = "password"
/// key_alias = "mykey"
/// key_password = "keypassword"
///
/// [android.permissions]
/// "android.permission.FOREGROUND_SERVICE" = { description = "Background service" }
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct AndroidConfig {
    // === Bundle settings (override [bundle] section) ===
    /// The app's identifier (e.g., "com.example.myapp").
    /// Overrides `bundle.identifier` for Android builds.
    #[serde(default)]
    pub identifier: Option<String>,

    /// The app's publisher.
    /// Overrides `bundle.publisher` for Android builds.
    #[serde(default)]
    pub publisher: Option<String>,

    /// Icons for the app.
    /// Overrides `bundle.icon` for Android builds.
    #[serde(default)]
    pub icon: Option<Vec<String>>,

    /// Additional resources to bundle.
    /// Overrides `bundle.resources` for Android builds.
    #[serde(default)]
    pub resources: Option<Vec<String>>,

    /// Copyright notice.
    /// Overrides `bundle.copyright` for Android builds.
    #[serde(default)]
    pub copyright: Option<String>,

    /// App category.
    /// Overrides `bundle.category` for Android builds.
    #[serde(default)]
    pub category: Option<String>,

    /// Short description.
    /// Overrides `bundle.short_description` for Android builds.
    #[serde(default)]
    pub short_description: Option<String>,

    /// Long description.
    /// Overrides `bundle.long_description` for Android builds.
    #[serde(default)]
    pub long_description: Option<String>,

    // === Android signing settings (previously in bundle.android) ===
    /// Android signing configuration for release builds.
    /// This replaces the deprecated `[bundle.android]` section.
    #[serde(default)]
    pub signing: Option<AndroidSigningConfig>,

    // === Android-specific settings ===
    /// Minimum SDK version.
    #[serde(default)]
    pub min_sdk: Option<u32>,

    /// Target SDK version.
    #[serde(default)]
    pub target_sdk: Option<u32>,

    /// Compile SDK version.
    #[serde(default)]
    pub compile_sdk: Option<u32>,

    /// Native library name loaded by NativeActivity (without `lib` prefix and `.so` extension).
    /// Defaults to `"main"` (i.e. `libmain.so`). Override if you need a custom library name.
    #[serde(default)]
    pub lib_name: Option<String>,

    /// Hardware/software features required.
    #[serde(default)]
    pub features: Vec<String>,

    /// Path to custom AndroidManifest.xml to merge.
    #[serde(default)]
    pub manifest: Option<PathBuf>,

    /// Gradle dependencies to add.
    #[serde(default)]
    pub gradle_dependencies: Vec<String>,

    /// Gradle plugins to apply.
    #[serde(default)]
    pub gradle_plugins: Vec<String>,

    /// ProGuard rule files.
    #[serde(default)]
    pub proguard_rules: Vec<PathBuf>,

    /// Additional Android permissions not in unified config.
    #[serde(default)]
    pub permissions: HashMap<String, RawPermission>,

    /// Raw XML injection points.
    #[serde(default)]
    pub raw: AndroidRawConfig,

    /// Application-level config.
    #[serde(default)]
    pub application: AndroidApplicationConfig,

    // === Platform-specific overrides (extend unified config) ===
    /// Additional URL schemes beyond unified `[deep_links]`.schemes.
    /// These are merged with the unified schemes.
    #[serde(default)]
    pub url_schemes: Vec<String>,

    /// Intent filters for deep linking.
    /// These extend the unified `[deep_links]` configuration with Android-specific options.
    #[serde(default)]
    pub intent_filters: Vec<AndroidIntentFilter>,

    /// Foreground service types for background operations.
    /// Valid values: "camera", "connectedDevice", "dataSync", "health", "location",
    /// "mediaPlayback", "mediaProjection", "microphone", "phoneCall", "remoteMessaging",
    /// "shortService", "specialUse", "systemExempted"
    #[serde(default)]
    pub foreground_service_types: Vec<String>,

    /// Queries for package visibility (required for Android 11+).
    /// Specify packages or intents your app needs to query.
    #[serde(default)]
    pub queries: AndroidQueries,
}

/// Android signing configuration for release builds.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AndroidSigningConfig {
    /// Path to the Java keystore file.
    pub jks_file: PathBuf,

    /// Password for the keystore.
    pub jks_password: String,

    /// Alias of the key in the keystore.
    pub key_alias: String,

    /// Password for the key.
    pub key_password: String,
}

/// Android intent filter for deep linking.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AndroidIntentFilter {
    /// Actions (e.g., "android.intent.action.VIEW").
    #[serde(default)]
    pub actions: Vec<String>,

    /// Categories (e.g., "android.intent.category.DEFAULT", "android.intent.category.BROWSABLE").
    #[serde(default)]
    pub categories: Vec<String>,

    /// Data specifications.
    #[serde(default)]
    pub data: Vec<AndroidIntentData>,

    /// Auto-verify for App Links (requires HTTPS and assetlinks.json).
    #[serde(default)]
    pub auto_verify: bool,
}

/// Android intent data specification.
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct AndroidIntentData {
    /// URL scheme (e.g., "https", "myapp").
    #[serde(default)]
    pub scheme: Option<String>,

    /// Host (e.g., "example.com").
    #[serde(default)]
    pub host: Option<String>,

    /// Port number.
    #[serde(default)]
    pub port: Option<String>,

    /// Path (exact match).
    #[serde(default)]
    pub path: Option<String>,

    /// Path prefix.
    #[serde(default)]
    pub path_prefix: Option<String>,

    /// Path pattern (with wildcards).
    #[serde(default)]
    pub path_pattern: Option<String>,

    /// MIME type.
    #[serde(default)]
    pub mime_type: Option<String>,
}

/// Android package visibility queries.
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct AndroidQueries {
    /// Package names to query.
    #[serde(default)]
    pub packages: Vec<String>,

    /// Intent actions to query.
    #[serde(default)]
    pub intents: Vec<AndroidQueryIntent>,
}

/// Android query intent specification.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AndroidQueryIntent {
    /// Action (e.g., "android.intent.action.SEND").
    pub action: String,

    /// Data scheme (e.g., "mailto").
    #[serde(default)]
    pub scheme: Option<String>,

    /// MIME type (e.g., "text/plain").
    #[serde(default)]
    pub mime_type: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct AndroidRawConfig {
    /// Raw XML to inject into manifest (after permissions).
    #[serde(default)]
    pub manifest: Option<String>,

    /// Raw attributes for `<application>` element.
    #[serde(default)]
    pub application_attrs: Option<String>,

    /// Raw XML inside `<application>` element.
    #[serde(default)]
    pub application: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct AndroidApplicationConfig {
    /// Enable cleartext (HTTP) traffic.
    #[serde(default)]
    pub uses_cleartext_traffic: Option<bool>,

    /// Application theme.
    #[serde(default)]
    pub theme: Option<String>,

    /// RTL layout support.
    #[serde(default)]
    pub supports_rtl: Option<bool>,

    /// Enable large heap.
    #[serde(default)]
    pub large_heap: Option<bool>,
}

// ============================================================================
// macOS Configuration
// ============================================================================

/// macOS-specific configuration.
///
/// Example:
/// ```toml
/// [macos]
/// minimum_system_version = "11.0"
/// identifier = "com.example.myapp.macos"  # Override bundle.identifier for macOS
///
/// # macOS signing (previously in [bundle.macos])
/// signing_identity = "Developer ID Application: My Company"
/// provider_short_name = "MYCOMPANY"
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct MacosConfig {
    // === Bundle settings (override [bundle] section) ===
    /// The app's identifier (e.g., "com.example.myapp").
    /// Overrides `bundle.identifier` for macOS builds.
    #[serde(default)]
    pub identifier: Option<String>,

    /// The app's publisher.
    /// Overrides `bundle.publisher` for macOS builds.
    #[serde(default)]
    pub publisher: Option<String>,

    /// Icons for the app.
    /// Overrides `bundle.icon` for macOS builds.
    #[serde(default)]
    pub icon: Option<Vec<String>>,

    /// Additional resources to bundle.
    /// Overrides `bundle.resources` for macOS builds.
    #[serde(default)]
    pub resources: Option<Vec<String>>,

    /// Copyright notice.
    /// Overrides `bundle.copyright` for macOS builds.
    #[serde(default)]
    pub copyright: Option<String>,

    /// Short description.
    /// Overrides `bundle.short_description` for macOS builds.
    #[serde(default)]
    pub short_description: Option<String>,

    /// Long description.
    /// Overrides `bundle.long_description` for macOS builds.
    #[serde(default)]
    pub long_description: Option<String>,

    // === macOS bundle settings (previously in bundle.macos) ===
    /// The bundle version string (CFBundleVersion).
    #[serde(default)]
    pub bundle_version: Option<String>,

    /// The bundle short version string (CFBundleShortVersionString).
    #[serde(default)]
    pub bundle_name: Option<String>,

    /// The signing identity to use for code signing.
    /// E.g., "Developer ID Application: My Company (TEAMID)"
    #[serde(default)]
    pub signing_identity: Option<String>,

    /// The provider short name for notarization.
    #[serde(default)]
    pub provider_short_name: Option<String>,

    /// Path to custom entitlements file for code signing.
    /// This overrides the generated entitlements.
    #[serde(default)]
    pub entitlements_file: Option<String>,

    /// Exception domain for App Transport Security.
    #[serde(default)]
    pub exception_domain: Option<String>,

    /// License file to include in DMG.
    #[serde(default)]
    pub license: Option<String>,

    /// Preserve the hardened runtime version flag.
    /// Setting this to false is useful when using an ad-hoc signature.
    #[serde(default)]
    pub hardened_runtime: Option<bool>,

    /// Additional files to include in the app bundle.
    /// Maps the path in the Contents directory to the source file path.
    #[serde(default)]
    pub files: HashMap<PathBuf, PathBuf>,

    // === macOS-specific settings ===
    /// Minimum macOS version (e.g., "11.0").
    #[serde(default)]
    pub minimum_system_version: Option<String>,

    /// Path to custom Info.plist.
    #[serde(default)]
    pub info_plist: Option<PathBuf>,

    /// Frameworks to embed.
    #[serde(default)]
    pub frameworks: Vec<String>,

    /// macOS entitlements.
    #[serde(default)]
    pub entitlements: MacosEntitlements,

    /// Additional Info.plist keys.
    #[serde(default)]
    pub plist: HashMap<String, serde_json::Value>,

    /// Raw injection points.
    #[serde(default)]
    pub raw: MacosRawConfig,

    // === Platform-specific overrides (extend unified config) ===
    /// Additional URL schemes beyond unified `[deep_links]`.schemes.
    /// These are merged with the unified schemes.
    #[serde(default)]
    pub url_schemes: Vec<String>,

    /// Document types the app can open (uses same format as iOS).
    #[serde(default)]
    pub document_types: Vec<IosDocumentType>,

    /// Exported type identifiers (custom UTIs).
    #[serde(default)]
    pub exported_type_identifiers: Vec<IosTypeIdentifier>,

    /// Imported type identifiers.
    #[serde(default)]
    pub imported_type_identifiers: Vec<IosTypeIdentifier>,

    /// App category for the Mac App Store.
    /// E.g., "public.app-category.productivity"
    #[serde(default)]
    pub category: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct MacosEntitlements {
    /// Enable App Sandbox.
    #[serde(default, rename = "app-sandbox")]
    pub app_sandbox: Option<bool>,

    /// User-selected file access (read-write).
    #[serde(default, rename = "files-user-selected")]
    pub files_user_selected: Option<bool>,

    /// User-selected file access (read-only).
    #[serde(default, rename = "files-user-selected-readonly")]
    pub files_user_selected_readonly: Option<bool>,

    /// Outgoing network connections.
    #[serde(default, rename = "network-client")]
    pub network_client: Option<bool>,

    /// Incoming network connections.
    #[serde(default, rename = "network-server")]
    pub network_server: Option<bool>,

    /// Camera access.
    #[serde(default)]
    pub camera: Option<bool>,

    /// Microphone access.
    #[serde(default)]
    pub microphone: Option<bool>,

    /// USB access.
    #[serde(default)]
    pub usb: Option<bool>,

    /// Bluetooth access.
    #[serde(default)]
    pub bluetooth: Option<bool>,

    /// Printing.
    #[serde(default)]
    pub print: Option<bool>,

    /// Location services.
    #[serde(default)]
    pub location: Option<bool>,

    /// Address book access.
    #[serde(default)]
    pub addressbook: Option<bool>,

    /// Calendars access.
    #[serde(default)]
    pub calendars: Option<bool>,

    /// Disable library validation.
    #[serde(default, rename = "disable-library-validation")]
    pub disable_library_validation: Option<bool>,

    /// Allow JIT.
    #[serde(default, rename = "allow-jit")]
    pub allow_jit: Option<bool>,

    /// Allow unsigned executable memory.
    #[serde(default, rename = "allow-unsigned-executable-memory")]
    pub allow_unsigned_executable_memory: Option<bool>,

    /// Additional entitlements.
    #[serde(flatten)]
    pub additional: HashMap<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct MacosRawConfig {
    /// Raw XML to inject into Info.plist.
    #[serde(default)]
    pub info_plist: Option<String>,

    /// Raw XML to inject into entitlements.plist.
    #[serde(default)]
    pub entitlements: Option<String>,
}

// ============================================================================
// Windows Configuration
// ============================================================================

/// Windows-specific configuration.
///
/// Example:
/// ```toml
/// [windows]
/// identifier = "com.example.myapp.windows"  # Override bundle.identifier for Windows
///
/// # Windows installer settings (previously in [bundle.windows])
/// [windows.nsis]
/// install_mode = "PerMachine"
///
/// [windows.wix]
/// language = [["en-US", null]]
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct WindowsConfig {
    // === Bundle settings (override [bundle] section) ===
    /// The app's identifier (e.g., "com.example.myapp").
    /// Overrides `bundle.identifier` for Windows builds.
    #[serde(default)]
    pub identifier: Option<String>,

    /// The app's publisher.
    /// Overrides `bundle.publisher` for Windows builds.
    #[serde(default)]
    pub publisher: Option<String>,

    /// Icons for the app.
    /// Overrides `bundle.icon` for Windows builds.
    #[serde(default)]
    pub icon: Option<Vec<String>>,

    /// Additional resources to bundle.
    /// Overrides `bundle.resources` for Windows builds.
    #[serde(default)]
    pub resources: Option<Vec<String>>,

    /// Copyright notice.
    /// Overrides `bundle.copyright` for Windows builds.
    #[serde(default)]
    pub copyright: Option<String>,

    /// App category.
    /// Overrides `bundle.category` for Windows builds.
    #[serde(default)]
    pub category: Option<String>,

    /// Short description.
    /// Overrides `bundle.short_description` for Windows builds.
    #[serde(default)]
    pub short_description: Option<String>,

    /// Long description.
    /// Overrides `bundle.long_description` for Windows builds.
    #[serde(default)]
    pub long_description: Option<String>,

    // === Windows bundle settings (previously in bundle.windows) ===
    /// Digest algorithm for code signing.
    #[serde(default)]
    pub digest_algorithm: Option<String>,

    /// Certificate thumbprint for code signing.
    #[serde(default)]
    pub certificate_thumbprint: Option<String>,

    /// Timestamp server URL for code signing.
    #[serde(default)]
    pub timestamp_url: Option<String>,

    /// Use TSP (RFC 3161) timestamp.
    #[serde(default)]
    pub tsp: Option<bool>,

    /// WiX installer settings.
    #[serde(default)]
    pub wix: Option<WindowsWixSettings>,

    /// NSIS installer settings.
    #[serde(default)]
    pub nsis: Option<WindowsNsisSettings>,

    /// Path to custom Windows icon.
    #[serde(default)]
    pub icon_path: Option<PathBuf>,

    /// WebView2 installation mode.
    #[serde(default)]
    pub webview_install_mode: Option<WindowsWebviewInstallMode>,

    /// Allow downgrades when installing.
    #[serde(default)]
    pub allow_downgrades: Option<bool>,

    /// Custom sign command.
    #[serde(default)]
    pub sign_command: Option<WindowsSignCommand>,

    // === Windows-specific settings ===
    /// UWP/MSIX capabilities.
    #[serde(default)]
    pub capabilities: Vec<String>,

    /// Restricted capabilities.
    #[serde(default)]
    pub restricted_capabilities: Vec<String>,

    /// Device capabilities.
    #[serde(default)]
    pub device_capabilities: Vec<String>,
}

/// WiX installer settings.
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct WindowsWixSettings {
    /// Languages and their locale paths.
    #[serde(default)]
    pub language: Vec<(String, Option<PathBuf>)>,

    /// Path to custom WiX template.
    #[serde(default)]
    pub template: Option<PathBuf>,

    /// WiX fragment files to include.
    #[serde(default)]
    pub fragment_paths: Vec<PathBuf>,

    /// Component group references.
    #[serde(default)]
    pub component_group_refs: Vec<String>,

    /// Component references.
    #[serde(default)]
    pub component_refs: Vec<String>,

    /// Feature group references.
    #[serde(default)]
    pub feature_group_refs: Vec<String>,

    /// Feature references.
    #[serde(default)]
    pub feature_refs: Vec<String>,

    /// Merge module references.
    #[serde(default)]
    pub merge_refs: Vec<String>,

    /// Skip WebView2 installation.
    #[serde(default)]
    pub skip_webview_install: Option<bool>,

    /// License file path.
    #[serde(default)]
    pub license: Option<PathBuf>,

    /// Enable elevated update task.
    #[serde(default)]
    pub enable_elevated_update_task: Option<bool>,

    /// Banner image path.
    #[serde(default)]
    pub banner_path: Option<PathBuf>,

    /// Dialog image path.
    #[serde(default)]
    pub dialog_image_path: Option<PathBuf>,

    /// FIPS compliant mode.
    #[serde(default)]
    pub fips_compliant: Option<bool>,

    /// MSI version string.
    #[serde(default)]
    pub version: Option<String>,

    /// MSI upgrade code (GUID).
    #[serde(default)]
    #[schemars(with = "Option<String>")]
    pub upgrade_code: Option<uuid::Uuid>,
}

/// NSIS installer settings.
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct WindowsNsisSettings {
    /// Path to custom NSIS template.
    #[serde(default)]
    pub template: Option<PathBuf>,

    /// License file path.
    #[serde(default)]
    pub license: Option<PathBuf>,

    /// Header image path.
    #[serde(default)]
    pub header_image: Option<PathBuf>,

    /// Sidebar image path.
    #[serde(default)]
    pub sidebar_image: Option<PathBuf>,

    /// Installer icon path.
    #[serde(default)]
    pub installer_icon: Option<PathBuf>,

    /// Installation mode: "CurrentUser", "PerMachine", or "Both".
    #[serde(default)]
    pub install_mode: Option<String>,

    /// Languages to include.
    #[serde(default)]
    pub languages: Option<Vec<String>>,

    /// Custom language files.
    #[serde(default)]
    pub custom_language_files: Option<HashMap<String, PathBuf>>,

    /// Display language selector.
    #[serde(default)]
    pub display_language_selector: Option<bool>,

    /// Start menu folder name.
    #[serde(default)]
    pub start_menu_folder: Option<String>,

    /// Installer hooks script path.
    #[serde(default)]
    pub installer_hooks: Option<PathBuf>,

    /// Minimum WebView2 version required.
    #[serde(default)]
    pub minimum_webview2_version: Option<String>,
}

/// WebView2 installation mode.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type")]
pub enum WindowsWebviewInstallMode {
    /// Skip WebView2 installation.
    Skip,
    /// Download bootstrapper.
    DownloadBootstrapper {
        #[serde(default)]
        silent: bool,
    },
    /// Embed bootstrapper.
    EmbedBootstrapper {
        #[serde(default)]
        silent: bool,
    },
    /// Use offline installer.
    OfflineInstaller {
        #[serde(default)]
        silent: bool,
    },
    /// Use fixed runtime from path.
    FixedRuntime { path: PathBuf },
}

/// Custom sign command for Windows code signing.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct WindowsSignCommand {
    /// The command to run.
    pub cmd: String,
    /// Command arguments. Use "%1" as placeholder for binary path.
    pub args: Vec<String>,
}

// ============================================================================
// Linux Configuration
// ============================================================================

/// Linux-specific configuration.
///
/// Example:
/// ```toml
/// [linux]
/// identifier = "com.example.myapp.linux"  # Override bundle.identifier for Linux
/// categories = ["Utility"]
///
/// # Debian package settings (previously in [bundle.deb])
/// [linux.deb]
/// depends = ["libwebkit2gtk-4.0-37"]
/// section = "utils"
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct LinuxConfig {
    // === Bundle settings (override [bundle] section) ===
    /// The app's identifier (e.g., "com.example.myapp").
    /// Overrides `bundle.identifier` for Linux builds.
    #[serde(default)]
    pub identifier: Option<String>,

    /// The app's publisher.
    /// Overrides `bundle.publisher` for Linux builds.
    #[serde(default)]
    pub publisher: Option<String>,

    /// Icons for the app.
    /// Overrides `bundle.icon` for Linux builds.
    #[serde(default)]
    pub icon: Option<Vec<String>>,

    /// Additional resources to bundle.
    /// Overrides `bundle.resources` for Linux builds.
    #[serde(default)]
    pub resources: Option<Vec<String>>,

    /// Copyright notice.
    /// Overrides `bundle.copyright` for Linux builds.
    #[serde(default)]
    pub copyright: Option<String>,

    /// App category.
    /// Overrides `bundle.category` for Linux builds.
    #[serde(default)]
    pub category: Option<String>,

    /// Short description.
    /// Overrides `bundle.short_description` for Linux builds.
    #[serde(default)]
    pub short_description: Option<String>,

    /// Long description.
    /// Overrides `bundle.long_description` for Linux builds.
    #[serde(default)]
    pub long_description: Option<String>,

    // === Debian package settings (previously in bundle.deb) ===
    /// Debian-specific package settings.
    #[serde(default)]
    pub deb: Option<LinuxDebSettings>,

    // === Linux-specific settings ===
    /// Flatpak sandbox permissions.
    #[serde(default)]
    pub flatpak_permissions: Vec<String>,

    /// D-Bus interfaces to access.
    #[serde(default)]
    pub dbus_access: Vec<String>,

    /// Desktop entry categories.
    #[serde(default)]
    pub categories: Vec<String>,

    /// Desktop entry keywords.
    #[serde(default)]
    pub keywords: Vec<String>,

    /// MIME types the app can handle.
    #[serde(default)]
    pub mime_types: Vec<String>,
}

/// Debian package settings.
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
pub struct LinuxDebSettings {
    /// Package dependencies.
    #[serde(default)]
    pub depends: Option<Vec<String>>,

    /// Recommended packages.
    #[serde(default)]
    pub recommends: Option<Vec<String>>,

    /// Packages this provides.
    #[serde(default)]
    pub provides: Option<Vec<String>>,

    /// Package conflicts.
    #[serde(default)]
    pub conflicts: Option<Vec<String>>,

    /// Packages this replaces.
    #[serde(default)]
    pub replaces: Option<Vec<String>>,

    /// Additional files to include. Maps package path to source path.
    #[serde(default)]
    pub files: HashMap<PathBuf, PathBuf>,

    /// Path to custom desktop template.
    #[serde(default)]
    pub desktop_template: Option<PathBuf>,

    /// Debian section (e.g., "utils", "web").
    #[serde(default)]
    pub section: Option<String>,

    /// Package priority ("required", "important", "standard", "optional", "extra").
    #[serde(default)]
    pub priority: Option<String>,

    /// Path to changelog file.
    #[serde(default)]
    pub changelog: Option<PathBuf>,

    /// Pre-install script path.
    #[serde(default)]
    pub pre_install_script: Option<PathBuf>,

    /// Post-install script path.
    #[serde(default)]
    pub post_install_script: Option<PathBuf>,

    /// Pre-remove script path.
    #[serde(default)]
    pub pre_remove_script: Option<PathBuf>,

    /// Post-remove script path.
    #[serde(default)]
    pub post_remove_script: Option<PathBuf>,
}

// ============================================================================
// Schema Generation
// ============================================================================

/// Generate a JSON schema for the complete Dioxus.toml configuration.
///
/// This can be used for IDE autocomplete when editing Dioxus.toml files.
/// The schema includes all configuration: application, web, bundle, permissions,
/// platform-specific settings, and more.
///
/// Note: Default values are stripped and allOf wrappers simplified to prevent
/// stack overflow in some TOML LSP implementations (e.g., Taplo's WASM build).
pub fn generate_manifest_schema() -> schemars::schema::RootSchema {
    let mut schema = schemars::schema_for!(super::DioxusConfig);

    // Simplify schema to prevent Taplo WASM LSP stack overflow.
    // 1. Strip default values (large nested objects cause issues)
    // 2. Simplify allOf wrappers around single $refs
    simplify_schema(&mut schema.schema);
    for def in schema.definitions.values_mut() {
        if let schemars::schema::Schema::Object(obj) = def {
            simplify_schema(obj);
        }
    }

    schema
}

/// Recursively simplify a schema object for LSP compatibility.
/// - Removes default values (large nested objects cause stack overflow)
/// - Simplifies `allOf: [$ref]` to just `$ref` (reduces recursion depth)
fn simplify_schema(schema: &mut schemars::schema::SchemaObject) {
    // Remove the default value from this schema
    schema.metadata().default = None;

    // Simplify allOf with single $ref: { allOf: [{ $ref: "..." }] } -> { $ref: "..." }
    let mut ref_to_promote = None;
    if let Some(subschemas) = &schema.subschemas {
        if let Some(all_of) = &subschemas.all_of {
            if all_of.len() == 1 {
                if let schemars::schema::Schema::Object(inner) = &all_of[0] {
                    if inner.reference.is_some()
                        && inner.instance_type.is_none()
                        && inner.object.is_none()
                        && inner.array.is_none()
                        && inner.subschemas.is_none()
                    {
                        ref_to_promote = inner.reference.clone();
                    }
                }
            }
        }
    }
    if let Some(r) = ref_to_promote {
        schema.subschemas = None;
        schema.reference = Some(r);
    }

    // Process remaining subschemas
    if let Some(subschemas) = &mut schema.subschemas {
        if let Some(all_of) = &mut subschemas.all_of {
            for s in all_of {
                if let schemars::schema::Schema::Object(obj) = s {
                    simplify_schema(obj);
                }
            }
        }
        if let Some(any_of) = &mut subschemas.any_of {
            for s in any_of {
                if let schemars::schema::Schema::Object(obj) = s {
                    simplify_schema(obj);
                }
            }
        }
        if let Some(one_of) = &mut subschemas.one_of {
            for s in one_of {
                if let schemars::schema::Schema::Object(obj) = s {
                    simplify_schema(obj);
                }
            }
        }
    }

    // Process object properties
    if let Some(object) = &mut schema.object {
        for prop in object.properties.values_mut() {
            if let schemars::schema::Schema::Object(obj) = prop {
                simplify_schema(obj);
            }
        }
        if let Some(additional) = &mut object.additional_properties {
            if let schemars::schema::Schema::Object(obj) = additional.as_mut() {
                simplify_schema(obj);
            }
        }
    }

    // Process array items
    if let Some(array) = &mut schema.array {
        if let Some(items) = &mut array.items {
            match items {
                schemars::schema::SingleOrVec::Single(s) => {
                    if let schemars::schema::Schema::Object(obj) = s.as_mut() {
                        simplify_schema(obj);
                    }
                }
                schemars::schema::SingleOrVec::Vec(v) => {
                    for s in v {
                        if let schemars::schema::Schema::Object(obj) = s {
                            simplify_schema(obj);
                        }
                    }
                }
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_parse_permissions() {
        let toml = r#"
            [permissions]
            location = { precision = "fine", description = "Track your runs" }
            camera = { description = "Take photos" }
        "#;

        #[derive(Deserialize)]
        struct Config {
            permissions: PermissionsConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        let loc = config.permissions.location.unwrap();
        assert_eq!(loc.precision, LocationPrecision::Fine);
        assert_eq!(loc.description, "Track your runs");
        assert!(config.permissions.camera.is_some());
    }

    #[test]
    fn test_parse_ios_config() {
        let toml = r#"
            [ios]
            deployment_target = "15.0"

            [ios.entitlements]
            app-groups = ["group.com.example.app"]
        "#;

        #[derive(Deserialize)]
        struct Config {
            ios: IosConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert_eq!(config.ios.deployment_target, Some("15.0".to_string()));
        assert_eq!(
            config.ios.entitlements.app_groups,
            vec!["group.com.example.app"]
        );
    }

    #[test]
    fn test_parse_android_config() {
        let toml = r#"
            [android]
            min_sdk = 24
            target_sdk = 34

            [android.permissions]
            "android.permission.FOREGROUND_SERVICE" = { description = "Background" }
        "#;

        #[derive(Deserialize)]
        struct Config {
            android: AndroidConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert_eq!(config.android.min_sdk, Some(24));
        assert!(config
            .android
            .permissions
            .contains_key("android.permission.FOREGROUND_SERVICE"));
    }

    #[test]
    fn test_parse_deep_links() {
        let toml = r#"
            [deep_links]
            schemes = ["myapp", "com.example.app"]
            hosts = ["example.com", "*.example.com"]
            paths = ["/app/*", "/share/*"]
        "#;

        #[derive(Deserialize)]
        struct Config {
            deep_links: DeepLinkConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert_eq!(config.deep_links.schemes, vec!["myapp", "com.example.app"]);
        assert_eq!(
            config.deep_links.hosts,
            vec!["example.com", "*.example.com"]
        );
        assert_eq!(config.deep_links.paths, vec!["/app/*", "/share/*"]);
    }

    #[test]
    fn test_parse_background_modes() {
        let toml = r#"
            [background]
            location = true
            audio = true
            fetch = true
            remote-notifications = true
        "#;

        #[derive(Deserialize)]
        struct Config {
            background: BackgroundConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert!(config.background.location);
        assert!(config.background.audio);
        assert!(config.background.fetch);
        assert!(config.background.remote_notifications);
        assert!(!config.background.voip);
    }

    #[test]
    fn test_parse_ios_url_schemes_and_background() {
        let toml = r#"
            [ios]
            deployment_target = "15.0"
            url_schemes = ["myapp-ios"]
            background_modes = ["location", "fetch", "remote-notification"]

            [[ios.document_types]]
            name = "My Document"
            extensions = ["mydoc"]
            role = "Editor"
        "#;

        #[derive(Deserialize)]
        struct Config {
            ios: IosConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert_eq!(config.ios.url_schemes, vec!["myapp-ios"]);
        assert_eq!(
            config.ios.background_modes,
            vec!["location", "fetch", "remote-notification"]
        );
        assert_eq!(config.ios.document_types.len(), 1);
        assert_eq!(config.ios.document_types[0].name, "My Document");
    }

    #[test]
    fn test_parse_android_intent_filters() {
        let toml = r#"
            [android]
            min_sdk = 24
            url_schemes = ["myapp-android"]
            foreground_service_types = ["location", "mediaPlayback"]

            [[android.intent_filters]]
            actions = ["android.intent.action.VIEW"]
            categories = ["android.intent.category.DEFAULT", "android.intent.category.BROWSABLE"]
            auto_verify = true

            [[android.intent_filters.data]]
            scheme = "https"
            host = "example.com"
            path_prefix = "/app"
        "#;

        #[derive(Deserialize)]
        struct Config {
            android: AndroidConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert_eq!(config.android.url_schemes, vec!["myapp-android"]);
        assert_eq!(
            config.android.foreground_service_types,
            vec!["location", "mediaPlayback"]
        );
        assert_eq!(config.android.intent_filters.len(), 1);
        assert!(config.android.intent_filters[0].auto_verify);
    }

    #[test]
    fn test_parse_macos_url_schemes() {
        let toml = r#"
            [macos]
            minimum_system_version = "11.0"
            url_schemes = ["myapp-macos"]
            category = "public.app-category.productivity"

            [[macos.document_types]]
            name = "My Format"
            extensions = ["myfmt"]
        "#;

        #[derive(Deserialize)]
        struct Config {
            macos: MacosConfig,
        }

        let config: Config = toml::from_str(toml).unwrap();
        assert_eq!(config.macos.url_schemes, vec!["myapp-macos"]);
        assert_eq!(
            config.macos.category,
            Some("public.app-category.productivity".to_string())
        );
        assert_eq!(config.macos.document_types.len(), 1);
    }

    #[test]
    fn test_generate_schema() {
        let schema = generate_manifest_schema();
        let json = serde_json::to_string_pretty(&schema).unwrap();

        // Verify the schema contains all top-level DioxusConfig types
        assert!(json.contains("ApplicationConfig"));
        assert!(json.contains("WebConfig"));
        assert!(json.contains("BundleConfig"));
        assert!(json.contains("ComponentConfig"));
        assert!(json.contains("PermissionsConfig"));
        assert!(json.contains("DeepLinkConfig"));
        assert!(json.contains("BackgroundConfig"));
        assert!(json.contains("IosConfig"));
        assert!(json.contains("AndroidConfig"));
        assert!(json.contains("MacosConfig"));
        assert!(json.contains("WindowsConfig"));
        assert!(json.contains("LinuxConfig"));

        // Verify some specific properties exist
        assert!(json.contains("location"));
        assert!(json.contains("camera"));
        assert!(json.contains("deployment_target"));
        assert!(json.contains("min_sdk"));

        // Verify application config properties
        assert!(json.contains("asset_dir"));
        assert!(json.contains("public_dir"));

        // Verify web config properties
        assert!(json.contains("pre_compress"));
        assert!(json.contains("wasm_opt"));

        // Verify bundle config properties
        assert!(json.contains("identifier"));
        assert!(json.contains("publisher"));
    }
}