itihas 1.5.0

Itihas — structured world history: civilizations, eras, events, historical figures, and calendar metadata
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
//! Major civilizations with geographic extent, peak period, and key traits.
//!
//! Provides [`Civilization`] structs, pre-built data for 53 major world
//! civilizations, and lookup functions by region and active year.
//!
//! # Sources
//!
//! Dates and traits: Stearns (2001), Trigger (2003). Chinese: Twitchett &
//! Fairbank (1978--2015). South Asian: Kulke & Rothermund (2016). African:
//! Connah (2015). Mesoamerican: Coe (2013). Scripts: Daniels & Bright (1996).
//! Full bibliography:
//! [`docs/sources/civilizations.md`](https://github.com/MacCracken/itihas/blob/main/docs/sources/civilizations.md).

use alloc::borrow::Cow;
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
use core::fmt;

use serde::{Deserialize, Serialize};

use crate::error::ItihasError;

/// A historical civilization.
///
/// Years use astronomical year numbering: negative = BCE, positive = CE.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Civilization {
    /// Name of the civilization.
    pub name: Cow<'static, str>,
    /// Primary geographic region.
    pub region: Cow<'static, str>,
    /// Era name during peak influence.
    pub peak_era: Cow<'static, str>,
    /// Approximate founding year (negative = BCE).
    pub founding_year: i32,
    /// Approximate end year (negative = BCE). `i32::MAX` for ongoing influence.
    pub end_year: i32,
    /// Key cultural/technological traits.
    pub traits: Vec<Cow<'static, str>>,
    /// Primary writing system or script.
    pub script: Cow<'static, str>,
    /// ISO 639 language codes associated with this civilization.
    pub language_codes: Vec<Cow<'static, str>>,
}

impl fmt::Display for Civilization {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        if self.end_year == i32::MAX {
            write!(
                f,
                "{} ({}, {} – present)",
                self.name, self.region, self.founding_year
            )
        } else {
            write!(
                f,
                "{} ({}, {}{})",
                self.name, self.region, self.founding_year, self.end_year
            )
        }
    }
}

fn build_civilizations() -> Vec<Civilization> {
    vec![
        Civilization {
            name: Cow::Borrowed("Mesopotamia"),
            region: Cow::Borrowed("Near East"),
            peak_era: Cow::Borrowed("Bronze Age"),
            founding_year: -3500,
            end_year: -539,
            traits: vec![
                Cow::Borrowed("cuneiform writing"),
                Cow::Borrowed("irrigation"),
                Cow::Borrowed("law codes"),
                Cow::Borrowed("astronomy"),
            ],
            script: Cow::Borrowed("Cuneiform"),
            language_codes: vec![Cow::Borrowed("akk"), Cow::Borrowed("sux")],
        },
        Civilization {
            name: Cow::Borrowed("Ancient Egypt"),
            region: Cow::Borrowed("North Africa"),
            peak_era: Cow::Borrowed("Bronze Age"),
            founding_year: -3100,
            end_year: -30,
            traits: vec![
                Cow::Borrowed("hieroglyphic writing"),
                Cow::Borrowed("pyramid construction"),
                Cow::Borrowed("mummification"),
                Cow::Borrowed("astronomy"),
            ],
            script: Cow::Borrowed("Hieroglyphic"),
            language_codes: vec![Cow::Borrowed("egy")],
        },
        Civilization {
            name: Cow::Borrowed("Indus Valley"),
            region: Cow::Borrowed("South Asia"),
            peak_era: Cow::Borrowed("Bronze Age"),
            founding_year: -3300,
            end_year: -1300,
            traits: vec![
                Cow::Borrowed("urban planning"),
                Cow::Borrowed("standardized weights"),
                Cow::Borrowed("drainage systems"),
                Cow::Borrowed("trade networks"),
            ],
            script: Cow::Borrowed("Indus script"),
            language_codes: vec![],
        },
        Civilization {
            name: Cow::Borrowed("Ancient China"),
            region: Cow::Borrowed("East Asia"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: -2070,
            end_year: 1912,
            traits: vec![
                Cow::Borrowed("paper"),
                Cow::Borrowed("gunpowder"),
                Cow::Borrowed("compass"),
                Cow::Borrowed("printing"),
            ],
            script: Cow::Borrowed("Chinese characters"),
            language_codes: vec![Cow::Borrowed("zh")],
        },
        Civilization {
            name: Cow::Borrowed("Ancient Greece"),
            region: Cow::Borrowed("Mediterranean"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: -800,
            end_year: -146,
            traits: vec![
                Cow::Borrowed("democracy"),
                Cow::Borrowed("philosophy"),
                Cow::Borrowed("theater"),
                Cow::Borrowed("mathematics"),
            ],
            script: Cow::Borrowed("Greek alphabet"),
            language_codes: vec![Cow::Borrowed("grc")],
        },
        Civilization {
            name: Cow::Borrowed("Roman Empire"),
            region: Cow::Borrowed("Mediterranean, Europe"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: -753,
            end_year: 476,
            traits: vec![
                Cow::Borrowed("engineering"),
                Cow::Borrowed("law"),
                Cow::Borrowed("roads"),
                Cow::Borrowed("aqueducts"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("la")],
        },
        Civilization {
            name: Cow::Borrowed("Maya"),
            region: Cow::Borrowed("Mesoamerica"),
            peak_era: Cow::Borrowed("Mesoamerican Classic"),
            founding_year: -2000,
            end_year: 1500,
            traits: vec![
                Cow::Borrowed("hieroglyphic writing"),
                Cow::Borrowed("calendar systems"),
                Cow::Borrowed("astronomy"),
                Cow::Borrowed("pyramids"),
            ],
            script: Cow::Borrowed("Maya script"),
            language_codes: vec![Cow::Borrowed("yua")],
        },
        Civilization {
            name: Cow::Borrowed("Persian Empire"),
            region: Cow::Borrowed("Near East, Central Asia"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: -550,
            end_year: -330,
            traits: vec![
                Cow::Borrowed("postal system"),
                Cow::Borrowed("road network"),
                Cow::Borrowed("religious tolerance"),
                Cow::Borrowed("administration"),
            ],
            script: Cow::Borrowed("Old Persian cuneiform"),
            language_codes: vec![Cow::Borrowed("peo")],
        },
        Civilization {
            name: Cow::Borrowed("Mongol Empire"),
            region: Cow::Borrowed("Central Asia, East Asia, Europe"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1206,
            end_year: 1368,
            traits: vec![
                Cow::Borrowed("cavalry warfare"),
                Cow::Borrowed("Silk Road trade"),
                Cow::Borrowed("religious tolerance"),
                Cow::Borrowed("postal relay"),
            ],
            script: Cow::Borrowed("Mongolian script"),
            language_codes: vec![Cow::Borrowed("mn")],
        },
        Civilization {
            name: Cow::Borrowed("Ottoman Empire"),
            region: Cow::Borrowed("Near East, Southeast Europe, North Africa"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1299,
            end_year: 1922,
            traits: vec![
                Cow::Borrowed("millet system"),
                Cow::Borrowed("architecture"),
                Cow::Borrowed("military innovation"),
                Cow::Borrowed("trade networks"),
            ],
            script: Cow::Borrowed("Ottoman Turkish script"),
            language_codes: vec![Cow::Borrowed("ota")],
        },
        // ── Sub-Saharan Africa ──────────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Kingdom of Kush"),
            region: Cow::Borrowed("East Africa"),
            peak_era: Cow::Borrowed("Iron Age"),
            founding_year: -1070,
            end_year: 350,
            traits: vec![
                Cow::Borrowed("iron smelting"),
                Cow::Borrowed("pyramid construction"),
                Cow::Borrowed("archery"),
                Cow::Borrowed("gold trade"),
            ],
            script: Cow::Borrowed("Meroitic script"),
            language_codes: vec![],
        },
        Civilization {
            name: Cow::Borrowed("Aksumite Empire"),
            region: Cow::Borrowed("East Africa"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: 100,
            end_year: 940,
            traits: vec![
                Cow::Borrowed("monumental stelae"),
                Cow::Borrowed("coinage"),
                Cow::Borrowed("Red Sea trade"),
                Cow::Borrowed("early Christianity"),
            ],
            script: Cow::Borrowed("Ge'ez script"),
            language_codes: vec![Cow::Borrowed("gez")],
        },
        Civilization {
            name: Cow::Borrowed("Ghana Empire"),
            region: Cow::Borrowed("West Africa"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 300,
            end_year: 1200,
            traits: vec![
                Cow::Borrowed("gold trade"),
                Cow::Borrowed("trans-Saharan commerce"),
                Cow::Borrowed("ironworking"),
                Cow::Borrowed("centralized governance"),
            ],
            script: Cow::Borrowed("Arabic script"),
            language_codes: vec![Cow::Borrowed("snk")],
        },
        Civilization {
            name: Cow::Borrowed("Mali Empire"),
            region: Cow::Borrowed("West Africa"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1235,
            end_year: 1600,
            traits: vec![
                Cow::Borrowed("Islamic scholarship"),
                Cow::Borrowed("Timbuktu universities"),
                Cow::Borrowed("gold trade"),
                Cow::Borrowed("oral tradition"),
            ],
            script: Cow::Borrowed("Arabic script"),
            language_codes: vec![Cow::Borrowed("bm")],
        },
        Civilization {
            name: Cow::Borrowed("Songhai Empire"),
            region: Cow::Borrowed("West Africa"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1430,
            end_year: 1591,
            traits: vec![
                Cow::Borrowed("riverine trade"),
                Cow::Borrowed("Islamic jurisprudence"),
                Cow::Borrowed("bureaucratic administration"),
            ],
            script: Cow::Borrowed("Arabic script"),
            language_codes: vec![Cow::Borrowed("son")],
        },
        Civilization {
            name: Cow::Borrowed("Great Zimbabwe"),
            region: Cow::Borrowed("Southern Africa"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1100,
            end_year: 1450,
            traits: vec![
                Cow::Borrowed("stone architecture"),
                Cow::Borrowed("cattle herding"),
                Cow::Borrowed("gold mining"),
                Cow::Borrowed("Indian Ocean trade"),
            ],
            script: Cow::Borrowed("oral tradition"),
            language_codes: vec![Cow::Borrowed("sn")],
        },
        Civilization {
            name: Cow::Borrowed("Kingdom of Kongo"),
            region: Cow::Borrowed("Central Africa"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1390,
            end_year: 1914,
            traits: vec![
                Cow::Borrowed("textile production"),
                Cow::Borrowed("metalworking"),
                Cow::Borrowed("diplomacy"),
                Cow::Borrowed("agriculture"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("kg")],
        },
        Civilization {
            name: Cow::Borrowed("Ethiopian Empire"),
            region: Cow::Borrowed("East Africa"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1270,
            end_year: 1974,
            traits: vec![
                Cow::Borrowed("rock-hewn churches"),
                Cow::Borrowed("Solomonic dynasty"),
                Cow::Borrowed("coffee cultivation"),
                Cow::Borrowed("manuscript tradition"),
            ],
            script: Cow::Borrowed("Ge'ez script"),
            language_codes: vec![Cow::Borrowed("am")],
        },
        // ── Southeast Asia ──────────────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Khmer Empire"),
            region: Cow::Borrowed("Southeast Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 802,
            end_year: 1431,
            traits: vec![
                Cow::Borrowed("temple architecture"),
                Cow::Borrowed("hydraulic engineering"),
                Cow::Borrowed("rice agriculture"),
                Cow::Borrowed("Hindu-Buddhist syncretism"),
            ],
            script: Cow::Borrowed("Khmer script"),
            language_codes: vec![Cow::Borrowed("km")],
        },
        Civilization {
            name: Cow::Borrowed("Srivijaya"),
            region: Cow::Borrowed("Southeast Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 650,
            end_year: 1377,
            traits: vec![
                Cow::Borrowed("maritime trade"),
                Cow::Borrowed("Buddhist scholarship"),
                Cow::Borrowed("thalassocracy"),
            ],
            script: Cow::Borrowed("Pallava script"),
            language_codes: vec![Cow::Borrowed("ms")],
        },
        Civilization {
            name: Cow::Borrowed("Majapahit"),
            region: Cow::Borrowed("Southeast Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1293,
            end_year: 1527,
            traits: vec![
                Cow::Borrowed("maritime empire"),
                Cow::Borrowed("literature"),
                Cow::Borrowed("Hindu-Buddhist culture"),
                Cow::Borrowed("spice trade"),
            ],
            script: Cow::Borrowed("Kawi script"),
            language_codes: vec![Cow::Borrowed("jv")],
        },
        Civilization {
            name: Cow::Borrowed("Pagan Kingdom"),
            region: Cow::Borrowed("Southeast Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 849,
            end_year: 1297,
            traits: vec![
                Cow::Borrowed("pagoda construction"),
                Cow::Borrowed("Theravada Buddhism"),
                Cow::Borrowed("irrigation systems"),
            ],
            script: Cow::Borrowed("Burmese script"),
            language_codes: vec![Cow::Borrowed("my")],
        },
        Civilization {
            name: Cow::Borrowed("Dai Viet"),
            region: Cow::Borrowed("Southeast Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 968,
            end_year: 1802,
            traits: vec![
                Cow::Borrowed("rice cultivation"),
                Cow::Borrowed("Confucian bureaucracy"),
                Cow::Borrowed("military resistance"),
                Cow::Borrowed("poetry"),
            ],
            script: Cow::Borrowed("Chu Nom script"),
            language_codes: vec![Cow::Borrowed("vi")],
        },
        Civilization {
            name: Cow::Borrowed("Ayutthaya Kingdom"),
            region: Cow::Borrowed("Southeast Asia"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1351,
            end_year: 1767,
            traits: vec![
                Cow::Borrowed("diplomacy"),
                Cow::Borrowed("international trade"),
                Cow::Borrowed("Buddhist art"),
                Cow::Borrowed("hydraulic management"),
            ],
            script: Cow::Borrowed("Thai script"),
            language_codes: vec![Cow::Borrowed("th")],
        },
        // ── Pacific Islands ─────────────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Tonga Empire"),
            region: Cow::Borrowed("Oceania"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 950,
            end_year: 1865,
            traits: vec![
                Cow::Borrowed("ocean navigation"),
                Cow::Borrowed("tapa cloth"),
                Cow::Borrowed("chieftain hierarchy"),
            ],
            script: Cow::Borrowed("oral tradition"),
            language_codes: vec![Cow::Borrowed("to")],
        },
        Civilization {
            name: Cow::Borrowed("Hawaiian Kingdom"),
            region: Cow::Borrowed("Oceania"),
            peak_era: Cow::Borrowed("Industrial Age"),
            founding_year: 1795,
            end_year: 1893,
            traits: vec![
                Cow::Borrowed("ahupuaa land management"),
                Cow::Borrowed("wayfinding navigation"),
                Cow::Borrowed("featherwork"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("haw")],
        },
        // ── Pre-Columbian Americas ──────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Olmec"),
            region: Cow::Borrowed("Mesoamerica"),
            peak_era: Cow::Borrowed("Mesoamerican Preclassic"),
            founding_year: -1500,
            end_year: -400,
            traits: vec![
                Cow::Borrowed("colossal stone heads"),
                Cow::Borrowed("ceremonial centers"),
                Cow::Borrowed("rubber processing"),
                Cow::Borrowed("jaguar worship"),
            ],
            script: Cow::Borrowed("Olmec script"),
            language_codes: vec![],
        },
        Civilization {
            name: Cow::Borrowed("Aztec Empire"),
            region: Cow::Borrowed("Mesoamerica"),
            peak_era: Cow::Borrowed("Mesoamerican Postclassic"),
            founding_year: 1428,
            end_year: 1521,
            traits: vec![
                Cow::Borrowed("chinampas agriculture"),
                Cow::Borrowed("tribute system"),
                Cow::Borrowed("monumental architecture"),
                Cow::Borrowed("calendar systems"),
            ],
            script: Cow::Borrowed("Aztec pictographs"),
            language_codes: vec![Cow::Borrowed("nah")],
        },
        Civilization {
            name: Cow::Borrowed("Inca Empire"),
            region: Cow::Borrowed("South America"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1438,
            end_year: 1533,
            traits: vec![
                Cow::Borrowed("road network"),
                Cow::Borrowed("terrace farming"),
                Cow::Borrowed("quipu record-keeping"),
                Cow::Borrowed("masonry"),
            ],
            script: Cow::Borrowed("Quipu"),
            language_codes: vec![Cow::Borrowed("qu")],
        },
        Civilization {
            name: Cow::Borrowed("Mississippian Culture"),
            region: Cow::Borrowed("North America"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 800,
            end_year: 1600,
            traits: vec![
                Cow::Borrowed("mound building"),
                Cow::Borrowed("maize agriculture"),
                Cow::Borrowed("chiefdom organization"),
                Cow::Borrowed("shell trade"),
            ],
            script: Cow::Borrowed("oral tradition"),
            language_codes: vec![],
        },
        Civilization {
            name: Cow::Borrowed("Muisca Confederation"),
            region: Cow::Borrowed("South America"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 600,
            end_year: 1541,
            traits: vec![
                Cow::Borrowed("goldworking"),
                Cow::Borrowed("emerald mining"),
                Cow::Borrowed("salt trade"),
            ],
            script: Cow::Borrowed("oral tradition"),
            language_codes: vec![],
        },
        Civilization {
            name: Cow::Borrowed("Tiwanaku"),
            region: Cow::Borrowed("South America"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 550,
            end_year: 1000,
            traits: vec![
                Cow::Borrowed("raised-field agriculture"),
                Cow::Borrowed("monolithic architecture"),
                Cow::Borrowed("high-altitude adaptation"),
            ],
            script: Cow::Borrowed("oral tradition"),
            language_codes: vec![Cow::Borrowed("ay")],
        },
        // ── Europe ──────────────────────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Byzantine Empire"),
            region: Cow::Borrowed("Mediterranean, Europe"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 330,
            end_year: 1453,
            traits: vec![
                Cow::Borrowed("Roman law codification"),
                Cow::Borrowed("Orthodox Christianity"),
                Cow::Borrowed("mosaic art"),
                Cow::Borrowed("Greek fire"),
            ],
            script: Cow::Borrowed("Greek alphabet"),
            language_codes: vec![Cow::Borrowed("grc")],
        },
        Civilization {
            name: Cow::Borrowed("Viking/Norse"),
            region: Cow::Borrowed("Northern Europe"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 793,
            end_year: 1066,
            traits: vec![
                Cow::Borrowed("longship navigation"),
                Cow::Borrowed("Norse mythology"),
                Cow::Borrowed("exploration"),
                Cow::Borrowed("saga literature"),
            ],
            script: Cow::Borrowed("Runic/Futhark"),
            language_codes: vec![Cow::Borrowed("non")],
        },
        Civilization {
            name: Cow::Borrowed("Carolingian Empire"),
            region: Cow::Borrowed("Europe"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 751,
            end_year: 888,
            traits: vec![
                Cow::Borrowed("Carolingian Renaissance"),
                Cow::Borrowed("feudalism"),
                Cow::Borrowed("manuscript production"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("la")],
        },
        Civilization {
            name: Cow::Borrowed("Kingdom of France"),
            region: Cow::Borrowed("Europe"),
            peak_era: Cow::Borrowed("Age of Enlightenment"),
            founding_year: 843,
            end_year: 1792,
            traits: vec![
                Cow::Borrowed("Gothic architecture"),
                Cow::Borrowed("Enlightenment philosophy"),
                Cow::Borrowed("courtly culture"),
                Cow::Borrowed("centralized monarchy"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("fr")],
        },
        Civilization {
            name: Cow::Borrowed("Holy Roman Empire"),
            region: Cow::Borrowed("Central Europe"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 800,
            end_year: 1806,
            traits: vec![
                Cow::Borrowed("imperial governance"),
                Cow::Borrowed("printing press"),
                Cow::Borrowed("Hanseatic trade"),
                Cow::Borrowed("Reformation"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("de")],
        },
        Civilization {
            name: Cow::Borrowed("Republic of Venice"),
            region: Cow::Borrowed("Mediterranean"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 697,
            end_year: 1797,
            traits: vec![
                Cow::Borrowed("maritime trade"),
                Cow::Borrowed("glassmaking"),
                Cow::Borrowed("republican governance"),
                Cow::Borrowed("Renaissance art"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("vec")],
        },
        Civilization {
            name: Cow::Borrowed("Spanish Empire"),
            region: Cow::Borrowed("Europe, Americas"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1469,
            end_year: 1975,
            traits: vec![
                Cow::Borrowed("colonial expansion"),
                Cow::Borrowed("silver trade"),
                Cow::Borrowed("Reconquista"),
                Cow::Borrowed("Catholic missions"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("es")],
        },
        Civilization {
            name: Cow::Borrowed("Portuguese Empire"),
            region: Cow::Borrowed("Europe, Africa, Asia"),
            peak_era: Cow::Borrowed("Renaissance"),
            founding_year: 1415,
            end_year: 1999,
            traits: vec![
                Cow::Borrowed("maritime exploration"),
                Cow::Borrowed("cartography"),
                Cow::Borrowed("spice trade"),
                Cow::Borrowed("colonial administration"),
            ],
            script: Cow::Borrowed("Latin alphabet"),
            language_codes: vec![Cow::Borrowed("pt")],
        },
        // ── Near East / Central Asia ────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Hittite Empire"),
            region: Cow::Borrowed("Near East"),
            peak_era: Cow::Borrowed("Bronze Age"),
            founding_year: -1600,
            end_year: -1178,
            traits: vec![
                Cow::Borrowed("iron metallurgy"),
                Cow::Borrowed("chariot warfare"),
                Cow::Borrowed("treaty diplomacy"),
                Cow::Borrowed("bilingual governance"),
            ],
            script: Cow::Borrowed("Cuneiform/Hieroglyphic Luwian"),
            language_codes: vec![Cow::Borrowed("hit")],
        },
        Civilization {
            name: Cow::Borrowed("Assyrian Empire"),
            region: Cow::Borrowed("Near East"),
            peak_era: Cow::Borrowed("Iron Age"),
            founding_year: -2500,
            end_year: -609,
            traits: vec![
                Cow::Borrowed("military engineering"),
                Cow::Borrowed("library of Ashurbanipal"),
                Cow::Borrowed("siege warfare"),
                Cow::Borrowed("imperial roads"),
            ],
            script: Cow::Borrowed("Cuneiform"),
            language_codes: vec![Cow::Borrowed("akk")],
        },
        Civilization {
            name: Cow::Borrowed("Phoenicia"),
            region: Cow::Borrowed("Near East, Mediterranean"),
            peak_era: Cow::Borrowed("Iron Age"),
            founding_year: -1500,
            end_year: -300,
            traits: vec![
                Cow::Borrowed("alphabet invention"),
                Cow::Borrowed("maritime trade"),
                Cow::Borrowed("purple dye production"),
                Cow::Borrowed("colonization"),
            ],
            script: Cow::Borrowed("Phoenician alphabet"),
            language_codes: vec![Cow::Borrowed("phn")],
        },
        Civilization {
            name: Cow::Borrowed("Parthian Empire"),
            region: Cow::Borrowed("Near East, Central Asia"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: -247,
            end_year: 224,
            traits: vec![
                Cow::Borrowed("horse archery"),
                Cow::Borrowed("Silk Road trade"),
                Cow::Borrowed("feudal governance"),
                Cow::Borrowed("Hellenistic synthesis"),
            ],
            script: Cow::Borrowed("Aramaic script"),
            language_codes: vec![Cow::Borrowed("xpr")],
        },
        Civilization {
            name: Cow::Borrowed("Sassanid Empire"),
            region: Cow::Borrowed("Near East"),
            peak_era: Cow::Borrowed("Classical Antiquity"),
            founding_year: 224,
            end_year: 651,
            traits: vec![
                Cow::Borrowed("Zoroastrian state religion"),
                Cow::Borrowed("academy of Gondishapur"),
                Cow::Borrowed("rock reliefs"),
                Cow::Borrowed("heavy cavalry"),
            ],
            script: Cow::Borrowed("Pahlavi script"),
            language_codes: vec![Cow::Borrowed("pal")],
        },
        Civilization {
            name: Cow::Borrowed("Arab Caliphates"),
            region: Cow::Borrowed("Near East"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 632,
            end_year: 1517,
            traits: vec![
                Cow::Borrowed("Islamic scholarship"),
                Cow::Borrowed("algebra and optics"),
                Cow::Borrowed("trade networks"),
                Cow::Borrowed("architectural innovation"),
            ],
            script: Cow::Borrowed("Arabic script"),
            language_codes: vec![Cow::Borrowed("ar")],
        },
        Civilization {
            name: Cow::Borrowed("Timurid Empire"),
            region: Cow::Borrowed("Central Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1370,
            end_year: 1507,
            traits: vec![
                Cow::Borrowed("Timurid Renaissance"),
                Cow::Borrowed("astronomical observatories"),
                Cow::Borrowed("miniature painting"),
                Cow::Borrowed("Persian literature"),
            ],
            script: Cow::Borrowed("Persian/Arabic script"),
            language_codes: vec![Cow::Borrowed("fa")],
        },
        // ── South Asia ──────────────────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Chola Dynasty"),
            region: Cow::Borrowed("South Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 300,
            end_year: 1279,
            traits: vec![
                Cow::Borrowed("naval power"),
                Cow::Borrowed("bronze sculpture"),
                Cow::Borrowed("temple architecture"),
                Cow::Borrowed("maritime trade"),
            ],
            script: Cow::Borrowed("Tamil script"),
            language_codes: vec![Cow::Borrowed("ta")],
        },
        Civilization {
            name: Cow::Borrowed("Vijayanagara Empire"),
            region: Cow::Borrowed("South Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 1336,
            end_year: 1646,
            traits: vec![
                Cow::Borrowed("Hindu patronage"),
                Cow::Borrowed("Hampi architecture"),
                Cow::Borrowed("diamond trade"),
                Cow::Borrowed("irrigation systems"),
            ],
            script: Cow::Borrowed("Kannada script"),
            language_codes: vec![Cow::Borrowed("kn")],
        },
        Civilization {
            name: Cow::Borrowed("Maratha Empire"),
            region: Cow::Borrowed("South Asia"),
            peak_era: Cow::Borrowed("Age of Enlightenment"),
            founding_year: 1674,
            end_year: 1818,
            traits: vec![
                Cow::Borrowed("guerrilla warfare"),
                Cow::Borrowed("naval innovation"),
                Cow::Borrowed("decentralized governance"),
            ],
            script: Cow::Borrowed("Modi script"),
            language_codes: vec![Cow::Borrowed("mr")],
        },
        Civilization {
            name: Cow::Borrowed("Sikh Empire"),
            region: Cow::Borrowed("South Asia"),
            peak_era: Cow::Borrowed("Industrial Age"),
            founding_year: 1799,
            end_year: 1849,
            traits: vec![
                Cow::Borrowed("military modernization"),
                Cow::Borrowed("religious pluralism"),
                Cow::Borrowed("Khalsa governance"),
            ],
            script: Cow::Borrowed("Gurmukhi script"),
            language_codes: vec![Cow::Borrowed("pa")],
        },
        // ── East Asia ───────────────────────────────────────────────────
        Civilization {
            name: Cow::Borrowed("Goryeo Dynasty"),
            region: Cow::Borrowed("East Asia"),
            peak_era: Cow::Borrowed("Middle Ages"),
            founding_year: 918,
            end_year: 1392,
            traits: vec![
                Cow::Borrowed("celadon pottery"),
                Cow::Borrowed("movable type printing"),
                Cow::Borrowed("Buddhist scholarship"),
                Cow::Borrowed("civil service examinations"),
            ],
            script: Cow::Borrowed("Hanja/Korean"),
            language_codes: vec![Cow::Borrowed("ko")],
        },
        Civilization {
            name: Cow::Borrowed("Tokugawa Shogunate"),
            region: Cow::Borrowed("East Asia"),
            peak_era: Cow::Borrowed("Age of Enlightenment"),
            founding_year: 1603,
            end_year: 1868,
            traits: vec![
                Cow::Borrowed("sakoku isolationism"),
                Cow::Borrowed("ukiyo-e art"),
                Cow::Borrowed("bushido culture"),
                Cow::Borrowed("urbanization"),
            ],
            script: Cow::Borrowed("Japanese script"),
            language_codes: vec![Cow::Borrowed("ja")],
        },
    ]
}

/// Returns all pre-built civilizations.
///
/// Data is computed once and cached for the lifetime of the process.
#[cfg(feature = "std")]
#[must_use]
#[inline]
pub fn all_civilizations() -> &'static [Civilization] {
    static DATA: std::sync::LazyLock<Vec<Civilization>> =
        std::sync::LazyLock::new(build_civilizations);
    &DATA
}

/// Returns all pre-built civilizations.
#[cfg(not(feature = "std"))]
#[must_use]
#[inline]
pub fn all_civilizations() -> Vec<Civilization> {
    build_civilizations()
}

/// Returns civilizations whose region contains the given substring (case-insensitive).
#[must_use]
#[inline]
pub fn by_region(region: &str) -> Vec<Civilization> {
    tracing::debug!(region, "looking up civilizations by region");
    let lower = region.to_lowercase();
    all_civilizations()
        .iter()
        .filter(|c| c.region.to_lowercase().contains(&lower))
        .cloned()
        .collect()
}

/// Returns civilizations that were active during the given year.
///
/// A civilization is considered active if `founding_year <= year <= end_year`.
#[must_use]
#[inline]
pub fn active_at(year: i32) -> Vec<Civilization> {
    tracing::debug!(year, "looking up civilizations active at year");
    all_civilizations()
        .iter()
        .filter(|c| year >= c.founding_year && year <= c.end_year)
        .cloned()
        .collect()
}

/// Look up a civilization by exact name (case-insensitive).
///
/// Returns `Err(ItihasError::UnknownCivilization)` if no civilization matches.
#[inline]
pub fn by_name(name: &str) -> Result<Civilization, ItihasError> {
    tracing::debug!(name, "looking up civilization by name");
    let lower = name.to_lowercase();
    all_civilizations()
        .iter()
        .find(|c| c.name.to_lowercase() == lower)
        .cloned()
        .ok_or_else(|| ItihasError::UnknownCivilization(String::from(name)))
}

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

    #[test]
    fn test_all_civilizations_count() {
        assert_eq!(all_civilizations().len(), 53);
    }

    #[test]
    fn test_by_region_near_east() {
        let civs = by_region("Near East");
        assert!(civs.iter().any(|c| c.name == "Mesopotamia"));
        assert!(civs.iter().any(|c| c.name == "Persian Empire"));
    }

    #[test]
    fn test_by_region_case_insensitive() {
        let civs = by_region("mediterranean");
        assert!(civs.iter().any(|c| c.name == "Ancient Greece"));
        assert!(civs.iter().any(|c| c.name == "Roman Empire"));
    }

    #[test]
    fn test_by_region_no_match() {
        let civs = by_region("Antarctica");
        assert!(civs.is_empty());
    }

    #[test]
    fn test_active_at_500_bce() {
        let civs = active_at(-500);
        let names: Vec<_> = civs.iter().map(|c| c.name.as_ref()).collect();
        assert!(names.contains(&"Ancient Egypt"));
        assert!(names.contains(&"Ancient Greece"));
        assert!(names.contains(&"Persian Empire"));
        assert!(names.contains(&"Ancient China"));
    }

    #[test]
    fn test_active_at_1300_ce() {
        let civs = active_at(1300);
        let names: Vec<_> = civs.iter().map(|c| c.name.as_ref()).collect();
        assert!(names.contains(&"Mongol Empire"));
        assert!(names.contains(&"Ottoman Empire"));
        assert!(names.contains(&"Maya"));
    }

    #[test]
    fn test_active_at_none() {
        let civs = active_at(-100_000);
        assert!(civs.is_empty());
    }

    #[test]
    fn test_civilization_serde_roundtrip() {
        let civs = all_civilizations();
        for civ in civs.iter() {
            let json = serde_json::to_string(civ).unwrap();
            let back: Civilization = serde_json::from_str(&json).unwrap();
            assert_eq!(civ, &back);
        }
    }
}