finance-query 2.5.1

A Rust library for querying financial data
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
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
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
use serde::{Deserialize, Serialize};

/// Predefined screener selectors for Yahoo Finance
pub mod screeners {
    /// Predefined Yahoo Finance screener selector
    ///
    /// Passed to `finance::screener()` or `client.get_screener()` to select one of the
    /// 15 built-in Yahoo Finance screeners (equity or fund).
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub enum Screener {
        // Equity screeners
        /// Small caps with high EPS growth, sorted by volume
        AggressiveSmallCaps,
        /// Top gaining stocks (>3% change, >$2B market cap)
        DayGainers,
        /// Top losing stocks (<-2.5% change, >$2B market cap)
        DayLosers,
        /// Tech stocks with 25%+ revenue and EPS growth
        GrowthTechnologyStocks,
        /// Most actively traded stocks by volume
        MostActives,
        /// Stocks with highest short interest percentage
        MostShortedStocks,
        /// Small cap gainers (<$2B market cap)
        SmallCapGainers,
        /// Low P/E (<20), low PEG (<1), high EPS growth (25%+)
        UndervaluedGrowthStocks,
        /// Large caps ($10B-$100B) with low P/E and PEG
        UndervaluedLargeCaps,
        // Fund screeners
        /// Low-risk foreign large cap funds (4-5 star rated)
        ConservativeForeignFunds,
        /// High yield bond funds (4-5 star rated)
        HighYieldBond,
        /// Large blend core funds (4-5 star rated)
        PortfolioAnchors,
        /// Large growth funds (4-5 star rated)
        SolidLargeGrowthFunds,
        /// Mid-cap growth funds (4-5 star rated)
        SolidMidcapGrowthFunds,
        /// Top performing mutual funds by percent change
        TopMutualFunds,
    }

    impl Screener {
        /// Convert to Yahoo Finance scrId parameter value (SCREAMING_SNAKE_CASE)
        pub fn as_scr_id(&self) -> &'static str {
            match self {
                Screener::AggressiveSmallCaps => "aggressive_small_caps",
                Screener::DayGainers => "day_gainers",
                Screener::DayLosers => "day_losers",
                Screener::GrowthTechnologyStocks => "growth_technology_stocks",
                Screener::MostActives => "most_actives",
                Screener::MostShortedStocks => "most_shorted_stocks",
                Screener::SmallCapGainers => "small_cap_gainers",
                Screener::UndervaluedGrowthStocks => "undervalued_growth_stocks",
                Screener::UndervaluedLargeCaps => "undervalued_large_caps",
                Screener::ConservativeForeignFunds => "conservative_foreign_funds",
                Screener::HighYieldBond => "high_yield_bond",
                Screener::PortfolioAnchors => "portfolio_anchors",
                Screener::SolidLargeGrowthFunds => "solid_large_growth_funds",
                Screener::SolidMidcapGrowthFunds => "solid_midcap_growth_funds",
                Screener::TopMutualFunds => "top_mutual_funds",
            }
        }

        /// Parse from string, returns None on invalid input
        ///
        /// # Example
        /// ```
        /// use finance_query::Screener;
        ///
        /// assert_eq!(Screener::parse("most-actives"), Some(Screener::MostActives));
        /// assert_eq!(Screener::parse("day-gainers"), Some(Screener::DayGainers));
        /// ```
        pub fn parse(s: &str) -> Option<Self> {
            s.parse().ok()
        }

        /// List all valid screener types for error messages
        pub fn valid_types() -> &'static str {
            "aggressive-small-caps, day-gainers, day-losers, growth-technology-stocks, \
             most-actives, most-shorted-stocks, small-cap-gainers, undervalued-growth-stocks, \
             undervalued-large-caps, conservative-foreign-funds, high-yield-bond, \
             portfolio-anchors, solid-large-growth-funds, solid-midcap-growth-funds, \
             top-mutual-funds"
        }

        /// Get all screener types as an array
        pub fn all() -> &'static [Screener] {
            &[
                Screener::AggressiveSmallCaps,
                Screener::DayGainers,
                Screener::DayLosers,
                Screener::GrowthTechnologyStocks,
                Screener::MostActives,
                Screener::MostShortedStocks,
                Screener::SmallCapGainers,
                Screener::UndervaluedGrowthStocks,
                Screener::UndervaluedLargeCaps,
                Screener::ConservativeForeignFunds,
                Screener::HighYieldBond,
                Screener::PortfolioAnchors,
                Screener::SolidLargeGrowthFunds,
                Screener::SolidMidcapGrowthFunds,
                Screener::TopMutualFunds,
            ]
        }
    }

    impl std::str::FromStr for Screener {
        type Err = ();

        fn from_str(s: &str) -> Result<Self, Self::Err> {
            match s.to_lowercase().replace('_', "-").as_str() {
                "aggressive-small-caps" => Ok(Screener::AggressiveSmallCaps),
                "day-gainers" | "gainers" => Ok(Screener::DayGainers),
                "day-losers" | "losers" => Ok(Screener::DayLosers),
                "growth-technology-stocks" | "growth-tech" => Ok(Screener::GrowthTechnologyStocks),
                "most-actives" | "actives" => Ok(Screener::MostActives),
                "most-shorted-stocks" | "most-shorted" => Ok(Screener::MostShortedStocks),
                "small-cap-gainers" => Ok(Screener::SmallCapGainers),
                "undervalued-growth-stocks" | "undervalued-growth" => {
                    Ok(Screener::UndervaluedGrowthStocks)
                }
                "undervalued-large-caps" | "undervalued-large" => {
                    Ok(Screener::UndervaluedLargeCaps)
                }
                "conservative-foreign-funds" => Ok(Screener::ConservativeForeignFunds),
                "high-yield-bond" => Ok(Screener::HighYieldBond),
                "portfolio-anchors" => Ok(Screener::PortfolioAnchors),
                "solid-large-growth-funds" => Ok(Screener::SolidLargeGrowthFunds),
                "solid-midcap-growth-funds" => Ok(Screener::SolidMidcapGrowthFunds),
                "top-mutual-funds" => Ok(Screener::TopMutualFunds),
                _ => Err(()),
            }
        }
    }
}

/// Yahoo Finance sector types
///
/// These are the 11 GICS sectors available on Yahoo Finance.
pub mod sectors {
    use serde::{Deserialize, Serialize};

    /// Market sector types available on Yahoo Finance
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
    #[serde(rename_all = "kebab-case")]
    pub enum Sector {
        /// Technology sector (software, semiconductors, hardware)
        Technology,
        /// Financial Services sector (banks, insurance, asset management)
        FinancialServices,
        /// Consumer Cyclical sector (retail, automotive, leisure)
        ConsumerCyclical,
        /// Communication Services sector (telecom, media, entertainment)
        CommunicationServices,
        /// Healthcare sector (pharma, biotech, medical devices)
        Healthcare,
        /// Industrials sector (aerospace, machinery, construction)
        Industrials,
        /// Consumer Defensive sector (food, beverages, household products)
        ConsumerDefensive,
        /// Energy sector (oil, gas, renewable energy)
        Energy,
        /// Basic Materials sector (chemicals, metals, mining)
        BasicMaterials,
        /// Real Estate sector (REITs, property management)
        RealEstate,
        /// Utilities sector (electric, gas, water utilities)
        Utilities,
    }

    impl Sector {
        /// Convert to Yahoo Finance API path segment (lowercase with hyphens)
        pub fn as_api_path(&self) -> &'static str {
            match self {
                Sector::Technology => "technology",
                Sector::FinancialServices => "financial-services",
                Sector::ConsumerCyclical => "consumer-cyclical",
                Sector::CommunicationServices => "communication-services",
                Sector::Healthcare => "healthcare",
                Sector::Industrials => "industrials",
                Sector::ConsumerDefensive => "consumer-defensive",
                Sector::Energy => "energy",
                Sector::BasicMaterials => "basic-materials",
                Sector::RealEstate => "real-estate",
                Sector::Utilities => "utilities",
            }
        }

        /// Get human-readable display name
        pub fn display_name(&self) -> &'static str {
            match self {
                Sector::Technology => "Technology",
                Sector::FinancialServices => "Financial Services",
                Sector::ConsumerCyclical => "Consumer Cyclical",
                Sector::CommunicationServices => "Communication Services",
                Sector::Healthcare => "Healthcare",
                Sector::Industrials => "Industrials",
                Sector::ConsumerDefensive => "Consumer Defensive",
                Sector::Energy => "Energy",
                Sector::BasicMaterials => "Basic Materials",
                Sector::RealEstate => "Real Estate",
                Sector::Utilities => "Utilities",
            }
        }

        /// List all valid sector types for error messages
        pub fn valid_types() -> &'static str {
            "technology, financial-services, consumer-cyclical, communication-services, \
             healthcare, industrials, consumer-defensive, energy, basic-materials, \
             real-estate, utilities"
        }

        /// Get all sector types as an array
        pub fn all() -> &'static [Sector] {
            &[
                Sector::Technology,
                Sector::FinancialServices,
                Sector::ConsumerCyclical,
                Sector::CommunicationServices,
                Sector::Healthcare,
                Sector::Industrials,
                Sector::ConsumerDefensive,
                Sector::Energy,
                Sector::BasicMaterials,
                Sector::RealEstate,
                Sector::Utilities,
            ]
        }
    }

    impl std::str::FromStr for Sector {
        type Err = ();

        fn from_str(s: &str) -> Result<Self, Self::Err> {
            match s.to_lowercase().replace('_', "-").as_str() {
                "technology" | "tech" => Ok(Sector::Technology),
                "financial-services" | "financials" | "financial" => Ok(Sector::FinancialServices),
                "consumer-cyclical" => Ok(Sector::ConsumerCyclical),
                "communication-services" | "communication" => Ok(Sector::CommunicationServices),
                "healthcare" | "health" => Ok(Sector::Healthcare),
                "industrials" | "industrial" => Ok(Sector::Industrials),
                "consumer-defensive" => Ok(Sector::ConsumerDefensive),
                "energy" => Ok(Sector::Energy),
                "basic-materials" | "materials" => Ok(Sector::BasicMaterials),
                "real-estate" | "realestate" => Ok(Sector::RealEstate),
                "utilities" | "utility" => Ok(Sector::Utilities),
                _ => Err(()),
            }
        }
    }

    impl std::fmt::Display for Sector {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            write!(f, "{}", self.display_name())
        }
    }

    impl From<Sector> for String {
        /// Returns the display name used by Yahoo Finance screener (e.g. `"Technology"`).
        fn from(v: Sector) -> Self {
            v.display_name().to_string()
        }
    }
}

/// World market indices
pub mod indices {
    /// Region categories for world indices
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub enum Region {
        /// North and South America
        Americas,
        /// European markets
        Europe,
        /// Asia and Pacific markets
        AsiaPacific,
        /// Middle East and Africa
        MiddleEastAfrica,
        /// Currency indices
        Currencies,
    }

    impl std::str::FromStr for Region {
        type Err = ();

        fn from_str(s: &str) -> Result<Self, Self::Err> {
            match s.to_lowercase().replace(['-', '_'], "").as_str() {
                "americas" | "america" => Ok(Region::Americas),
                "europe" | "eu" => Ok(Region::Europe),
                "asiapacific" | "asia" | "apac" => Ok(Region::AsiaPacific),
                "middleeastafrica" | "mea" | "emea" => Ok(Region::MiddleEastAfrica),
                "currencies" | "currency" | "fx" => Ok(Region::Currencies),
                _ => Err(()),
            }
        }
    }

    impl Region {
        /// Parse from string, returns None on invalid input
        pub fn parse(s: &str) -> Option<Self> {
            s.parse().ok()
        }

        /// Get the symbols for this region
        pub fn symbols(&self) -> &'static [&'static str] {
            match self {
                Region::Americas => AMERICAS,
                Region::Europe => EUROPE,
                Region::AsiaPacific => ASIA_PACIFIC,
                Region::MiddleEastAfrica => MIDDLE_EAST_AFRICA,
                Region::Currencies => CURRENCIES,
            }
        }

        /// Convert to string representation
        pub fn as_str(&self) -> &'static str {
            match self {
                Region::Americas => "americas",
                Region::Europe => "europe",
                Region::AsiaPacific => "asia-pacific",
                Region::MiddleEastAfrica => "middle-east-africa",
                Region::Currencies => "currencies",
            }
        }

        /// All region variants
        pub fn all() -> &'static [Region] {
            &[
                Region::Americas,
                Region::Europe,
                Region::AsiaPacific,
                Region::MiddleEastAfrica,
                Region::Currencies,
            ]
        }
    }

    /// Americas indices
    pub const AMERICAS: &[&str] = &[
        "^GSPC",   // S&P 500
        "^DJI",    // Dow Jones Industrial Average
        "^IXIC",   // NASDAQ Composite
        "^NYA",    // NYSE Composite Index
        "^XAX",    // NYSE American Composite Index
        "^RUT",    // Russell 2000 Index
        "^VIX",    // CBOE Volatility Index
        "^GSPTSE", // S&P/TSX Composite (Canada)
        "^BVSP",   // IBOVESPA (Brazil)
        "^MXX",    // IPC MEXICO
        "^IPSA",   // S&P IPSA (Chile)
        "^MERV",   // MERVAL (Argentina)
    ];

    /// Europe indices
    pub const EUROPE: &[&str] = &[
        "^FTSE",            // FTSE 100 (UK)
        "^GDAXI",           // DAX (Germany)
        "^FCHI",            // CAC 40 (France)
        "^STOXX50E",        // EURO STOXX 50
        "^N100",            // Euronext 100 Index
        "^BFX",             // BEL 20 (Belgium)
        "^BUK100P",         // Cboe UK 100
        "MOEX.ME",          // Moscow Exchange
        "^125904-USD-STRD", // MSCI EUROPE
    ];

    /// Asia Pacific indices
    pub const ASIA_PACIFIC: &[&str] = &[
        "^N225",     // Nikkei 225 (Japan)
        "^HSI",      // Hang Seng Index (Hong Kong)
        "000001.SS", // SSE Composite Index (China)
        "^KS11",     // KOSPI (South Korea)
        "^TWII",     // Taiwan Weighted Index
        "^STI",      // STI Index (Singapore)
        "^AXJO",     // S&P/ASX 200 (Australia)
        "^AORD",     // All Ordinaries (Australia)
        "^NZ50",     // S&P/NZX 50 (New Zealand)
        "^BSESN",    // S&P BSE SENSEX (India)
        "^JKSE",     // IDX Composite (Indonesia)
        "^KLSE",     // FTSE Bursa Malaysia KLCI
    ];

    /// Middle East & Africa indices
    pub const MIDDLE_EAST_AFRICA: &[&str] = &[
        "^TA125.TA", // TA-125 (Israel)
        "^CASE30",   // EGX 30 (Egypt)
        "^JN0U.JO",  // Top 40 USD Net TRI (South Africa)
    ];

    /// Currency indices
    pub const CURRENCIES: &[&str] = &[
        "DX-Y.NYB", // US Dollar Index
        "^XDB",     // British Pound Currency Index
        "^XDE",     // Euro Currency Index
        "^XDN",     // Japanese Yen Currency Index
        "^XDA",     // Australian Dollar Currency Index
    ];

    /// All world indices (all regions combined)
    pub fn all_symbols() -> Vec<&'static str> {
        Region::all()
            .iter()
            .flat_map(|r| r.symbols().iter().copied())
            .collect()
    }
}

/// Fundamental timeseries field types for financial statements
///
/// These constants represent field names that must be prefixed with frequency ("annual" or "quarterly")
/// Example: "annualTotalRevenue", "quarterlyTotalRevenue"
#[allow(missing_docs)]
pub mod fundamental_types {
    // ==================
    // INCOME STATEMENT (48 fields)
    // ==================
    pub const TOTAL_REVENUE: &str = "TotalRevenue";
    pub const OPERATING_REVENUE: &str = "OperatingRevenue";
    pub const COST_OF_REVENUE: &str = "CostOfRevenue";
    pub const GROSS_PROFIT: &str = "GrossProfit";
    pub const OPERATING_EXPENSE: &str = "OperatingExpense";
    pub const SELLING_GENERAL_AND_ADMIN: &str = "SellingGeneralAndAdministration";
    pub const RESEARCH_AND_DEVELOPMENT: &str = "ResearchAndDevelopment";
    pub const OPERATING_INCOME: &str = "OperatingIncome";
    pub const NET_INTEREST_INCOME: &str = "NetInterestIncome";
    pub const INTEREST_EXPENSE: &str = "InterestExpense";
    pub const INTEREST_INCOME: &str = "InterestIncome";
    pub const NET_NON_OPERATING_INTEREST_INCOME_EXPENSE: &str =
        "NetNonOperatingInterestIncomeExpense";
    pub const OTHER_INCOME_EXPENSE: &str = "OtherIncomeExpense";
    pub const PRETAX_INCOME: &str = "PretaxIncome";
    pub const TAX_PROVISION: &str = "TaxProvision";
    pub const NET_INCOME_COMMON_STOCKHOLDERS: &str = "NetIncomeCommonStockholders";
    pub const NET_INCOME: &str = "NetIncome";
    pub const DILUTED_EPS: &str = "DilutedEPS";
    pub const BASIC_EPS: &str = "BasicEPS";
    pub const DILUTED_AVERAGE_SHARES: &str = "DilutedAverageShares";
    pub const BASIC_AVERAGE_SHARES: &str = "BasicAverageShares";
    pub const EBIT: &str = "EBIT";
    pub const EBITDA: &str = "EBITDA";
    pub const RECONCILED_COST_OF_REVENUE: &str = "ReconciledCostOfRevenue";
    pub const RECONCILED_DEPRECIATION: &str = "ReconciledDepreciation";
    pub const NET_INCOME_FROM_CONTINUING_OPERATION_NET_MINORITY_INTEREST: &str =
        "NetIncomeFromContinuingOperationNetMinorityInterest";
    pub const NORMALIZED_EBITDA: &str = "NormalizedEBITDA";
    pub const TOTAL_EXPENSES: &str = "TotalExpenses";
    pub const TOTAL_OPERATING_INCOME_AS_REPORTED: &str = "TotalOperatingIncomeAsReported";

    // ==================
    // BALANCE SHEET (42 fields)
    // ==================
    pub const TOTAL_ASSETS: &str = "TotalAssets";
    pub const CURRENT_ASSETS: &str = "CurrentAssets";
    pub const CASH_CASH_EQUIVALENTS_AND_SHORT_TERM_INVESTMENTS: &str =
        "CashCashEquivalentsAndShortTermInvestments";
    pub const CASH_AND_CASH_EQUIVALENTS: &str = "CashAndCashEquivalents";
    pub const CASH_FINANCIAL: &str = "CashFinancial";
    pub const RECEIVABLES: &str = "Receivables";
    pub const ACCOUNTS_RECEIVABLE: &str = "AccountsReceivable";
    pub const INVENTORY: &str = "Inventory";
    pub const PREPAID_ASSETS: &str = "PrepaidAssets";
    pub const OTHER_CURRENT_ASSETS: &str = "OtherCurrentAssets";
    pub const TOTAL_NON_CURRENT_ASSETS: &str = "TotalNonCurrentAssets";
    pub const NET_PPE: &str = "NetPPE";
    pub const GROSS_PPE: &str = "GrossPPE";
    pub const ACCUMULATED_DEPRECIATION: &str = "AccumulatedDepreciation";
    pub const GOODWILL: &str = "Goodwill";
    pub const GOODWILL_AND_OTHER_INTANGIBLE_ASSETS: &str = "GoodwillAndOtherIntangibleAssets";
    pub const OTHER_INTANGIBLE_ASSETS: &str = "OtherIntangibleAssets";
    pub const INVESTMENTS_AND_ADVANCES: &str = "InvestmentsAndAdvances";
    pub const LONG_TERM_EQUITY_INVESTMENT: &str = "LongTermEquityInvestment";
    pub const OTHER_NON_CURRENT_ASSETS: &str = "OtherNonCurrentAssets";
    pub const TOTAL_LIABILITIES_NET_MINORITY_INTEREST: &str = "TotalLiabilitiesNetMinorityInterest";
    pub const CURRENT_LIABILITIES: &str = "CurrentLiabilities";
    pub const PAYABLES_AND_ACCRUED_EXPENSES: &str = "PayablesAndAccruedExpenses";
    pub const ACCOUNTS_PAYABLE: &str = "AccountsPayable";
    pub const CURRENT_DEBT: &str = "CurrentDebt";
    pub const CURRENT_DEFERRED_REVENUE: &str = "CurrentDeferredRevenue";
    pub const OTHER_CURRENT_LIABILITIES: &str = "OtherCurrentLiabilities";
    pub const TOTAL_NON_CURRENT_LIABILITIES_NET_MINORITY_INTEREST: &str =
        "TotalNonCurrentLiabilitiesNetMinorityInterest";
    pub const LONG_TERM_DEBT: &str = "LongTermDebt";
    pub const LONG_TERM_DEBT_AND_CAPITAL_LEASE_OBLIGATION: &str =
        "LongTermDebtAndCapitalLeaseObligation";
    pub const NON_CURRENT_DEFERRED_REVENUE: &str = "NonCurrentDeferredRevenue";
    pub const NON_CURRENT_DEFERRED_TAXES_LIABILITIES: &str = "NonCurrentDeferredTaxesLiabilities";
    pub const OTHER_NON_CURRENT_LIABILITIES: &str = "OtherNonCurrentLiabilities";
    pub const STOCKHOLDERS_EQUITY: &str = "StockholdersEquity";
    pub const COMMON_STOCK_EQUITY: &str = "CommonStockEquity";
    pub const COMMON_STOCK: &str = "CommonStock";
    pub const RETAINED_EARNINGS: &str = "RetainedEarnings";
    pub const ADDITIONAL_PAID_IN_CAPITAL: &str = "AdditionalPaidInCapital";
    pub const TREASURY_STOCK: &str = "TreasuryStock";
    pub const TOTAL_EQUITY_GROSS_MINORITY_INTEREST: &str = "TotalEquityGrossMinorityInterest";
    pub const WORKING_CAPITAL: &str = "WorkingCapital";
    pub const INVESTED_CAPITAL: &str = "InvestedCapital";
    pub const TANGIBLE_BOOK_VALUE: &str = "TangibleBookValue";
    pub const TOTAL_DEBT: &str = "TotalDebt";
    pub const NET_DEBT: &str = "NetDebt";
    pub const SHARE_ISSUED: &str = "ShareIssued";
    pub const ORDINARY_SHARES_NUMBER: &str = "OrdinarySharesNumber";

    // ==================
    // CASH FLOW STATEMENT (48 fields)
    // ==================
    pub const OPERATING_CASH_FLOW: &str = "OperatingCashFlow";
    pub const CASH_FLOW_FROM_CONTINUING_OPERATING_ACTIVITIES: &str =
        "CashFlowFromContinuingOperatingActivities";
    pub const NET_INCOME_FROM_CONTINUING_OPERATIONS: &str = "NetIncomeFromContinuingOperations";
    pub const DEPRECIATION_AND_AMORTIZATION: &str = "DepreciationAndAmortization";
    pub const DEFERRED_INCOME_TAX: &str = "DeferredIncomeTax";
    pub const CHANGE_IN_WORKING_CAPITAL: &str = "ChangeInWorkingCapital";
    pub const CHANGE_IN_RECEIVABLES: &str = "ChangeInReceivables";
    pub const CHANGES_IN_ACCOUNT_RECEIVABLES: &str = "ChangesInAccountReceivables";
    pub const CHANGE_IN_INVENTORY: &str = "ChangeInInventory";
    pub const CHANGE_IN_ACCOUNT_PAYABLE: &str = "ChangeInAccountPayable";
    pub const CHANGE_IN_OTHER_WORKING_CAPITAL: &str = "ChangeInOtherWorkingCapital";
    pub const STOCK_BASED_COMPENSATION: &str = "StockBasedCompensation";
    pub const OTHER_NON_CASH_ITEMS: &str = "OtherNonCashItems";
    pub const INVESTING_CASH_FLOW: &str = "InvestingCashFlow";
    pub const CASH_FLOW_FROM_CONTINUING_INVESTING_ACTIVITIES: &str =
        "CashFlowFromContinuingInvestingActivities";
    pub const NET_PPE_PURCHASE_AND_SALE: &str = "NetPPEPurchaseAndSale";
    pub const PURCHASE_OF_PPE: &str = "PurchaseOfPPE";
    pub const SALE_OF_PPE: &str = "SaleOfPPE";
    pub const CAPITAL_EXPENDITURE: &str = "CapitalExpenditure";
    pub const NET_BUSINESS_PURCHASE_AND_SALE: &str = "NetBusinessPurchaseAndSale";
    pub const PURCHASE_OF_BUSINESS: &str = "PurchaseOfBusiness";
    pub const SALE_OF_BUSINESS: &str = "SaleOfBusiness";
    pub const NET_INVESTMENT_PURCHASE_AND_SALE: &str = "NetInvestmentPurchaseAndSale";
    pub const PURCHASE_OF_INVESTMENT: &str = "PurchaseOfInvestment";
    pub const SALE_OF_INVESTMENT: &str = "SaleOfInvestment";
    pub const NET_OTHER_INVESTING_CHANGES: &str = "NetOtherInvestingChanges";
    pub const FINANCING_CASH_FLOW: &str = "FinancingCashFlow";
    pub const CASH_FLOW_FROM_CONTINUING_FINANCING_ACTIVITIES: &str =
        "CashFlowFromContinuingFinancingActivities";
    pub const NET_ISSUANCE_PAYMENTS_OF_DEBT: &str = "NetIssuancePaymentsOfDebt";
    pub const NET_LONG_TERM_DEBT_ISSUANCE: &str = "NetLongTermDebtIssuance";
    pub const LONG_TERM_DEBT_ISSUANCE: &str = "LongTermDebtIssuance";
    pub const LONG_TERM_DEBT_PAYMENTS: &str = "LongTermDebtPayments";
    pub const NET_SHORT_TERM_DEBT_ISSUANCE: &str = "NetShortTermDebtIssuance";
    pub const NET_COMMON_STOCK_ISSUANCE: &str = "NetCommonStockIssuance";
    pub const COMMON_STOCK_ISSUANCE: &str = "CommonStockIssuance";
    pub const COMMON_STOCK_PAYMENTS: &str = "CommonStockPayments";
    pub const REPURCHASE_OF_CAPITAL_STOCK: &str = "RepurchaseOfCapitalStock";
    pub const CASH_DIVIDENDS_PAID: &str = "CashDividendsPaid";
    pub const COMMON_STOCK_DIVIDEND_PAID: &str = "CommonStockDividendPaid";
    pub const NET_OTHER_FINANCING_CHARGES: &str = "NetOtherFinancingCharges";
    pub const END_CASH_POSITION: &str = "EndCashPosition";
    pub const BEGINNING_CASH_POSITION: &str = "BeginningCashPosition";
    pub const CHANGESIN_CASH: &str = "ChangesinCash";
    pub const EFFECT_OF_EXCHANGE_RATE_CHANGES: &str = "EffectOfExchangeRateChanges";
    pub const FREE_CASH_FLOW: &str = "FreeCashFlow";
    pub const CAPITAL_EXPENDITURE_REPORTED: &str = "CapitalExpenditureReported";
}

/// Statement types for financial data
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StatementType {
    /// Income statement
    Income,
    /// Balance sheet
    Balance,
    /// Cash flow statement
    CashFlow,
}

impl StatementType {
    /// Convert statement type to string representation
    pub fn as_str(&self) -> &'static str {
        match self {
            StatementType::Income => "income",
            StatementType::Balance => "balance",
            StatementType::CashFlow => "cashflow",
        }
    }

    /// Get the list of fields for this statement type
    ///
    /// Returns field names without frequency prefix (e.g., "TotalRevenue" not "annualTotalRevenue")
    pub fn get_fields(&self) -> &'static [&'static str] {
        match self {
            StatementType::Income => &INCOME_STATEMENT_FIELDS,
            StatementType::Balance => &BALANCE_SHEET_FIELDS,
            StatementType::CashFlow => &CASH_FLOW_FIELDS,
        }
    }
}

/// Income statement fields (without frequency prefix)
const INCOME_STATEMENT_FIELDS: [&str; 30] = [
    fundamental_types::TOTAL_REVENUE,
    fundamental_types::OPERATING_REVENUE,
    fundamental_types::COST_OF_REVENUE,
    fundamental_types::GROSS_PROFIT,
    fundamental_types::OPERATING_EXPENSE,
    fundamental_types::SELLING_GENERAL_AND_ADMIN,
    fundamental_types::RESEARCH_AND_DEVELOPMENT,
    fundamental_types::OPERATING_INCOME,
    fundamental_types::NET_INTEREST_INCOME,
    fundamental_types::INTEREST_EXPENSE,
    fundamental_types::INTEREST_INCOME,
    fundamental_types::NET_NON_OPERATING_INTEREST_INCOME_EXPENSE,
    fundamental_types::OTHER_INCOME_EXPENSE,
    fundamental_types::PRETAX_INCOME,
    fundamental_types::TAX_PROVISION,
    fundamental_types::NET_INCOME_COMMON_STOCKHOLDERS,
    fundamental_types::NET_INCOME,
    fundamental_types::DILUTED_EPS,
    fundamental_types::BASIC_EPS,
    fundamental_types::DILUTED_AVERAGE_SHARES,
    fundamental_types::BASIC_AVERAGE_SHARES,
    fundamental_types::EBIT,
    fundamental_types::EBITDA,
    fundamental_types::RECONCILED_COST_OF_REVENUE,
    fundamental_types::RECONCILED_DEPRECIATION,
    fundamental_types::NET_INCOME_FROM_CONTINUING_OPERATION_NET_MINORITY_INTEREST,
    fundamental_types::NORMALIZED_EBITDA,
    fundamental_types::TOTAL_EXPENSES,
    fundamental_types::TOTAL_OPERATING_INCOME_AS_REPORTED,
    fundamental_types::DEPRECIATION_AND_AMORTIZATION,
];

/// Balance sheet fields (without frequency prefix)
const BALANCE_SHEET_FIELDS: [&str; 48] = [
    fundamental_types::TOTAL_ASSETS,
    fundamental_types::CURRENT_ASSETS,
    fundamental_types::CASH_CASH_EQUIVALENTS_AND_SHORT_TERM_INVESTMENTS,
    fundamental_types::CASH_AND_CASH_EQUIVALENTS,
    fundamental_types::CASH_FINANCIAL,
    fundamental_types::RECEIVABLES,
    fundamental_types::ACCOUNTS_RECEIVABLE,
    fundamental_types::INVENTORY,
    fundamental_types::PREPAID_ASSETS,
    fundamental_types::OTHER_CURRENT_ASSETS,
    fundamental_types::TOTAL_NON_CURRENT_ASSETS,
    fundamental_types::NET_PPE,
    fundamental_types::GROSS_PPE,
    fundamental_types::ACCUMULATED_DEPRECIATION,
    fundamental_types::GOODWILL,
    fundamental_types::GOODWILL_AND_OTHER_INTANGIBLE_ASSETS,
    fundamental_types::OTHER_INTANGIBLE_ASSETS,
    fundamental_types::INVESTMENTS_AND_ADVANCES,
    fundamental_types::LONG_TERM_EQUITY_INVESTMENT,
    fundamental_types::OTHER_NON_CURRENT_ASSETS,
    fundamental_types::TOTAL_LIABILITIES_NET_MINORITY_INTEREST,
    fundamental_types::CURRENT_LIABILITIES,
    fundamental_types::PAYABLES_AND_ACCRUED_EXPENSES,
    fundamental_types::ACCOUNTS_PAYABLE,
    fundamental_types::CURRENT_DEBT,
    fundamental_types::CURRENT_DEFERRED_REVENUE,
    fundamental_types::OTHER_CURRENT_LIABILITIES,
    fundamental_types::TOTAL_NON_CURRENT_LIABILITIES_NET_MINORITY_INTEREST,
    fundamental_types::LONG_TERM_DEBT,
    fundamental_types::LONG_TERM_DEBT_AND_CAPITAL_LEASE_OBLIGATION,
    fundamental_types::NON_CURRENT_DEFERRED_REVENUE,
    fundamental_types::NON_CURRENT_DEFERRED_TAXES_LIABILITIES,
    fundamental_types::OTHER_NON_CURRENT_LIABILITIES,
    fundamental_types::STOCKHOLDERS_EQUITY,
    fundamental_types::COMMON_STOCK_EQUITY,
    fundamental_types::COMMON_STOCK,
    fundamental_types::RETAINED_EARNINGS,
    fundamental_types::ADDITIONAL_PAID_IN_CAPITAL,
    fundamental_types::TREASURY_STOCK,
    fundamental_types::TOTAL_EQUITY_GROSS_MINORITY_INTEREST,
    fundamental_types::WORKING_CAPITAL,
    fundamental_types::INVESTED_CAPITAL,
    fundamental_types::TANGIBLE_BOOK_VALUE,
    fundamental_types::TOTAL_DEBT,
    fundamental_types::NET_DEBT,
    fundamental_types::SHARE_ISSUED,
    fundamental_types::ORDINARY_SHARES_NUMBER,
    fundamental_types::DEPRECIATION_AND_AMORTIZATION,
];

/// Cash flow statement fields (without frequency prefix)
const CASH_FLOW_FIELDS: [&str; 47] = [
    fundamental_types::OPERATING_CASH_FLOW,
    fundamental_types::CASH_FLOW_FROM_CONTINUING_OPERATING_ACTIVITIES,
    fundamental_types::NET_INCOME_FROM_CONTINUING_OPERATIONS,
    fundamental_types::DEPRECIATION_AND_AMORTIZATION,
    fundamental_types::DEFERRED_INCOME_TAX,
    fundamental_types::CHANGE_IN_WORKING_CAPITAL,
    fundamental_types::CHANGE_IN_RECEIVABLES,
    fundamental_types::CHANGES_IN_ACCOUNT_RECEIVABLES,
    fundamental_types::CHANGE_IN_INVENTORY,
    fundamental_types::CHANGE_IN_ACCOUNT_PAYABLE,
    fundamental_types::CHANGE_IN_OTHER_WORKING_CAPITAL,
    fundamental_types::STOCK_BASED_COMPENSATION,
    fundamental_types::OTHER_NON_CASH_ITEMS,
    fundamental_types::INVESTING_CASH_FLOW,
    fundamental_types::CASH_FLOW_FROM_CONTINUING_INVESTING_ACTIVITIES,
    fundamental_types::NET_PPE_PURCHASE_AND_SALE,
    fundamental_types::PURCHASE_OF_PPE,
    fundamental_types::SALE_OF_PPE,
    fundamental_types::CAPITAL_EXPENDITURE,
    fundamental_types::NET_BUSINESS_PURCHASE_AND_SALE,
    fundamental_types::PURCHASE_OF_BUSINESS,
    fundamental_types::SALE_OF_BUSINESS,
    fundamental_types::NET_INVESTMENT_PURCHASE_AND_SALE,
    fundamental_types::PURCHASE_OF_INVESTMENT,
    fundamental_types::SALE_OF_INVESTMENT,
    fundamental_types::NET_OTHER_INVESTING_CHANGES,
    fundamental_types::FINANCING_CASH_FLOW,
    fundamental_types::CASH_FLOW_FROM_CONTINUING_FINANCING_ACTIVITIES,
    fundamental_types::NET_ISSUANCE_PAYMENTS_OF_DEBT,
    fundamental_types::NET_LONG_TERM_DEBT_ISSUANCE,
    fundamental_types::LONG_TERM_DEBT_ISSUANCE,
    fundamental_types::LONG_TERM_DEBT_PAYMENTS,
    fundamental_types::NET_SHORT_TERM_DEBT_ISSUANCE,
    fundamental_types::NET_COMMON_STOCK_ISSUANCE,
    fundamental_types::COMMON_STOCK_ISSUANCE,
    fundamental_types::COMMON_STOCK_PAYMENTS,
    fundamental_types::REPURCHASE_OF_CAPITAL_STOCK,
    fundamental_types::CASH_DIVIDENDS_PAID,
    fundamental_types::COMMON_STOCK_DIVIDEND_PAID,
    fundamental_types::NET_OTHER_FINANCING_CHARGES,
    fundamental_types::END_CASH_POSITION,
    fundamental_types::BEGINNING_CASH_POSITION,
    fundamental_types::CHANGESIN_CASH,
    fundamental_types::EFFECT_OF_EXCHANGE_RATE_CHANGES,
    fundamental_types::FREE_CASH_FLOW,
    fundamental_types::CAPITAL_EXPENDITURE_REPORTED,
    fundamental_types::DEPRECIATION_AND_AMORTIZATION,
];

/// Frequency for financial data (annual or quarterly)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Frequency {
    /// Annual financial data
    Annual,
    /// Quarterly financial data
    Quarterly,
}

impl Frequency {
    /// Convert frequency to string representation
    pub fn as_str(&self) -> &'static str {
        match self {
            Frequency::Annual => "annual",
            Frequency::Quarterly => "quarterly",
        }
    }

    /// Build a fundamental type string with frequency prefix
    ///
    /// # Example
    ///
    /// ```
    /// use finance_query::Frequency;
    ///
    /// let field = Frequency::Annual.prefix("TotalRevenue");
    /// assert_eq!(field, "annualTotalRevenue");
    /// ```
    pub fn prefix(&self, field: &str) -> String {
        format!("{}{}", self.as_str(), field)
    }
}

/// Chart intervals
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Interval {
    /// 1 minute
    #[serde(rename = "1m")]
    OneMinute,
    /// 5 minutes
    #[serde(rename = "5m")]
    FiveMinutes,
    /// 15 minutes
    #[serde(rename = "15m")]
    FifteenMinutes,
    /// 30 minutes
    #[serde(rename = "30m")]
    ThirtyMinutes,
    /// 1 hour
    #[serde(rename = "1h")]
    OneHour,
    /// 1 day
    #[serde(rename = "1d")]
    OneDay,
    /// 1 week
    #[serde(rename = "1wk")]
    OneWeek,
    /// 1 month
    #[serde(rename = "1mo")]
    OneMonth,
    /// 3 months
    #[serde(rename = "3mo")]
    ThreeMonths,
}

impl Interval {
    /// Convert interval to Yahoo Finance API format
    pub fn as_str(&self) -> &'static str {
        match self {
            Interval::OneMinute => "1m",
            Interval::FiveMinutes => "5m",
            Interval::FifteenMinutes => "15m",
            Interval::ThirtyMinutes => "30m",
            Interval::OneHour => "1h",
            Interval::OneDay => "1d",
            Interval::OneWeek => "1wk",
            Interval::OneMonth => "1mo",
            Interval::ThreeMonths => "3mo",
        }
    }
}

impl std::fmt::Display for Interval {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Time ranges for chart data
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TimeRange {
    /// 1 day
    #[serde(rename = "1d")]
    OneDay,
    /// 5 days
    #[serde(rename = "5d")]
    FiveDays,
    /// 1 month
    #[serde(rename = "1mo")]
    OneMonth,
    /// 3 months
    #[serde(rename = "3mo")]
    ThreeMonths,
    /// 6 months
    #[serde(rename = "6mo")]
    SixMonths,
    /// 1 year
    #[serde(rename = "1y")]
    OneYear,
    /// 2 years
    #[serde(rename = "2y")]
    TwoYears,
    /// 5 years
    #[serde(rename = "5y")]
    FiveYears,
    /// 10 years
    #[serde(rename = "10y")]
    TenYears,
    /// Year to date
    #[serde(rename = "ytd")]
    YearToDate,
    /// Maximum available
    #[serde(rename = "max")]
    Max,
}

impl TimeRange {
    /// Convert time range to Yahoo Finance API format
    pub fn as_str(&self) -> &'static str {
        match self {
            TimeRange::OneDay => "1d",
            TimeRange::FiveDays => "5d",
            TimeRange::OneMonth => "1mo",
            TimeRange::ThreeMonths => "3mo",
            TimeRange::SixMonths => "6mo",
            TimeRange::OneYear => "1y",
            TimeRange::TwoYears => "2y",
            TimeRange::FiveYears => "5y",
            TimeRange::TenYears => "10y",
            TimeRange::YearToDate => "ytd",
            TimeRange::Max => "max",
        }
    }
}

impl std::fmt::Display for TimeRange {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Supported regions for Yahoo Finance regional APIs
///
/// Each region has predefined language and region codes that work together.
/// Using the Region enum ensures correct lang/region pairing.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Region {
    /// Argentina (es-AR, AR)
    Argentina,
    /// Australia (en-AU, AU)
    Australia,
    /// Brazil (pt-BR, BR)
    Brazil,
    /// Canada (en-CA, CA)
    Canada,
    /// China (zh-CN, CN)
    China,
    /// Denmark (da-DK, DK)
    Denmark,
    /// Finland (fi-FI, FI)
    Finland,
    /// France (fr-FR, FR)
    France,
    /// Germany (de-DE, DE)
    Germany,
    /// Greece (el-GR, GR)
    Greece,
    /// Hong Kong (zh-Hant-HK, HK)
    HongKong,
    /// India (en-IN, IN)
    India,
    /// Israel (he-IL, IL)
    Israel,
    /// Italy (it-IT, IT)
    Italy,
    /// Malaysia (ms-MY, MY)
    Malaysia,
    /// New Zealand (en-NZ, NZ)
    NewZealand,
    /// Norway (nb-NO, NO)
    Norway,
    /// Portugal (pt-PT, PT)
    Portugal,
    /// Russia (ru-RU, RU)
    Russia,
    /// Singapore (en-SG, SG)
    Singapore,
    /// Spain (es-ES, ES)
    Spain,
    /// Sweden (sv-SE, SE)
    Sweden,
    /// Taiwan (zh-TW, TW)
    Taiwan,
    /// Thailand (th-TH, TH)
    Thailand,
    /// Turkey (tr-TR, TR)
    Turkey,
    /// United Kingdom (en-GB, GB)
    UnitedKingdom,
    /// United States (en-US, US) - Default
    #[default]
    UnitedStates,
    /// Vietnam (vi-VN, VN)
    Vietnam,
}

impl Region {
    /// Get the language code for this region
    ///
    /// # Example
    ///
    /// ```
    /// use finance_query::Region;
    ///
    /// assert_eq!(Region::France.lang(), "fr-FR");
    /// assert_eq!(Region::UnitedStates.lang(), "en-US");
    /// ```
    pub fn lang(&self) -> &'static str {
        match self {
            Region::Argentina => "es-AR",
            Region::Australia => "en-AU",
            Region::Brazil => "pt-BR",
            Region::Canada => "en-CA",
            Region::China => "zh-CN",
            Region::Denmark => "da-DK",
            Region::Finland => "fi-FI",
            Region::France => "fr-FR",
            Region::Germany => "de-DE",
            Region::Greece => "el-GR",
            Region::HongKong => "zh-Hant-HK",
            Region::India => "en-IN",
            Region::Israel => "he-IL",
            Region::Italy => "it-IT",
            Region::Malaysia => "ms-MY",
            Region::NewZealand => "en-NZ",
            Region::Norway => "nb-NO",
            Region::Portugal => "pt-PT",
            Region::Russia => "ru-RU",
            Region::Singapore => "en-SG",
            Region::Spain => "es-ES",
            Region::Sweden => "sv-SE",
            Region::Taiwan => "zh-TW",
            Region::Thailand => "th-TH",
            Region::Turkey => "tr-TR",
            Region::UnitedKingdom => "en-GB",
            Region::UnitedStates => "en-US",
            Region::Vietnam => "vi-VN",
        }
    }

    /// Get the region code for this region
    ///
    /// # Example
    ///
    /// ```
    /// use finance_query::Region;
    ///
    /// assert_eq!(Region::France.region(), "FR");
    /// assert_eq!(Region::UnitedStates.region(), "US");
    /// ```
    pub fn region(&self) -> &'static str {
        match self {
            Region::Argentina => "AR",
            Region::Australia => "AU",
            Region::Brazil => "BR",
            Region::Canada => "CA",
            Region::China => "CN",
            Region::Denmark => "DK",
            Region::Finland => "FI",
            Region::France => "FR",
            Region::Germany => "DE",
            Region::Greece => "GR",
            Region::HongKong => "HK",
            Region::India => "IN",
            Region::Israel => "IL",
            Region::Italy => "IT",
            Region::Malaysia => "MY",
            Region::NewZealand => "NZ",
            Region::Norway => "NO",
            Region::Portugal => "PT",
            Region::Russia => "RU",
            Region::Singapore => "SG",
            Region::Spain => "ES",
            Region::Sweden => "SE",
            Region::Taiwan => "TW",
            Region::Thailand => "TH",
            Region::Turkey => "TR",
            Region::UnitedKingdom => "GB",
            Region::UnitedStates => "US",
            Region::Vietnam => "VN",
        }
    }

    /// Get the CORS domain for this region
    ///
    /// # Example
    ///
    /// ```
    /// use finance_query::Region;
    ///
    /// assert_eq!(Region::UnitedStates.cors_domain(), "finance.yahoo.com");
    /// assert_eq!(Region::France.cors_domain(), "fr.finance.yahoo.com");
    /// ```
    pub fn cors_domain(&self) -> &'static str {
        match self {
            Region::Argentina => "ar.finance.yahoo.com",
            Region::Australia => "au.finance.yahoo.com",
            Region::Brazil => "br.financas.yahoo.com",
            Region::Canada => "ca.finance.yahoo.com",
            Region::China => "cn.finance.yahoo.com",
            Region::Denmark => "dk.finance.yahoo.com",
            Region::Finland => "fi.finance.yahoo.com",
            Region::France => "fr.finance.yahoo.com",
            Region::Germany => "de.finance.yahoo.com",
            Region::Greece => "gr.finance.yahoo.com",
            Region::HongKong => "hk.finance.yahoo.com",
            Region::India => "in.finance.yahoo.com",
            Region::Israel => "il.finance.yahoo.com",
            Region::Italy => "it.finance.yahoo.com",
            Region::Malaysia => "my.finance.yahoo.com",
            Region::NewZealand => "nz.finance.yahoo.com",
            Region::Norway => "no.finance.yahoo.com",
            Region::Portugal => "pt.finance.yahoo.com",
            Region::Russia => "ru.finance.yahoo.com",
            Region::Singapore => "sg.finance.yahoo.com",
            Region::Spain => "es.finance.yahoo.com",
            Region::Sweden => "se.finance.yahoo.com",
            Region::Taiwan => "tw.finance.yahoo.com",
            Region::Thailand => "th.finance.yahoo.com",
            Region::Turkey => "tr.finance.yahoo.com",
            Region::UnitedKingdom => "uk.finance.yahoo.com",
            Region::UnitedStates => "finance.yahoo.com",
            Region::Vietnam => "vn.finance.yahoo.com",
        }
    }

    /// UTC offset in seconds for the region's primary exchange.
    ///
    /// Returns the standard-time (non-DST) UTC offset of each country's main
    /// exchange. This is used by the backtesting engine to align higher-timeframe
    /// resampling bucket boundaries to local calendar weeks and months, preventing
    /// APAC and other non-UTC exchanges from having bars mis-bucketed into the
    /// prior week due to UTC midnight falling inside their local trading day.
    ///
    /// # Note
    ///
    /// DST transitions are not modelled. For exchanges in regions with DST
    /// (e.g. NYSE, LSE) the boundary shift is at most ±1 hour and affects only
    /// the transition candles. This is a deliberate simplification — exact DST
    /// handling would require a timezone database dependency.
    pub const fn utc_offset_secs(&self) -> i64 {
        match self {
            // UTC-5 (NYSE/TSX winter)
            Region::UnitedStates | Region::Canada => -18_000,
            // UTC-3 (BYMA / B3 winter)
            Region::Argentina | Region::Brazil => -10_800,
            // UTC+0 (LSE / Euronext Lisbon)
            Region::UnitedKingdom | Region::Portugal => 0,
            // UTC+1 (Euronext Paris/Amsterdam/Milan/Madrid, Oslo, Stockholm, Copenhagen, Helsinki)
            Region::France
            | Region::Germany
            | Region::Italy
            | Region::Spain
            | Region::Norway
            | Region::Sweden
            | Region::Denmark
            | Region::Finland => 3_600,
            // UTC+2 (Athens, Tel Aviv, Moscow — note Russia stays UTC+3 year-round)
            Region::Greece | Region::Israel => 7_200,
            // UTC+3 (MOEX — no DST since 2014)
            Region::Turkey | Region::Russia => 10_800,
            // UTC+5:30 (BSE/NSE — India has no DST)
            Region::India => 19_800,
            // UTC+7 (SET Bangkok, HSX Hanoi)
            Region::Thailand | Region::Vietnam => 25_200,
            // UTC+8 (SSE/SZSE, HKEX, SGX, Bursa Malaysia, TWSE)
            Region::China
            | Region::HongKong
            | Region::Singapore
            | Region::Malaysia
            | Region::Taiwan => 28_800,
            // UTC+10 (ASX — AEST winter)
            Region::Australia => 36_000,
            // UTC+12 (NZX — NZST winter)
            Region::NewZealand => 43_200,
        }
    }
}

impl std::str::FromStr for Region {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_uppercase().as_str() {
            "AR" => Ok(Region::Argentina),
            "AU" => Ok(Region::Australia),
            "BR" => Ok(Region::Brazil),
            "CA" => Ok(Region::Canada),
            "CN" => Ok(Region::China),
            "DK" => Ok(Region::Denmark),
            "FI" => Ok(Region::Finland),
            "FR" => Ok(Region::France),
            "DE" => Ok(Region::Germany),
            "GR" => Ok(Region::Greece),
            "HK" => Ok(Region::HongKong),
            "IN" => Ok(Region::India),
            "IL" => Ok(Region::Israel),
            "IT" => Ok(Region::Italy),
            "MY" => Ok(Region::Malaysia),
            "NZ" => Ok(Region::NewZealand),
            "NO" => Ok(Region::Norway),
            "PT" => Ok(Region::Portugal),
            "RU" => Ok(Region::Russia),
            "SG" => Ok(Region::Singapore),
            "ES" => Ok(Region::Spain),
            "SE" => Ok(Region::Sweden),
            "TW" => Ok(Region::Taiwan),
            "TH" => Ok(Region::Thailand),
            "TR" => Ok(Region::Turkey),
            "GB" | "UK" => Ok(Region::UnitedKingdom),
            "US" => Ok(Region::UnitedStates),
            "VN" => Ok(Region::Vietnam),
            _ => Err(()),
        }
    }
}

impl From<Region> for String {
    /// Returns the lowercase two-letter country code used by the Yahoo Finance screener
    /// (e.g. `"us"`, `"gb"`).
    fn from(v: Region) -> Self {
        v.region().to_lowercase()
    }
}

/// Value format for API responses
///
/// Controls how `FormattedValue<T>` fields are serialized in responses.
/// This allows API consumers to choose between raw numeric values,
/// human-readable formatted strings, or both.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum ValueFormat {
    /// Return only raw numeric values (e.g., `123.45`) - default
    /// Best for programmatic use, calculations, charts
    #[default]
    Raw,
    /// Return only formatted strings (e.g., `"$123.45"`, `"1.2B"`)
    /// Best for display purposes
    Pretty,
    /// Return both raw and formatted values
    /// Returns the full `{raw, fmt, longFmt}` object
    Both,
}

impl std::str::FromStr for ValueFormat {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "raw" => Ok(ValueFormat::Raw),
            "pretty" | "fmt" => Ok(ValueFormat::Pretty),
            "both" | "full" => Ok(ValueFormat::Both),
            _ => Err(()),
        }
    }
}

impl ValueFormat {
    /// Parse from string (case-insensitive), returns None on invalid input
    pub fn parse(s: &str) -> Option<Self> {
        s.parse().ok()
    }

    /// Convert to string representation
    pub fn as_str(&self) -> &'static str {
        match self {
            ValueFormat::Raw => "raw",
            ValueFormat::Pretty => "pretty",
            ValueFormat::Both => "both",
        }
    }

    /// Transform a JSON value based on this format
    ///
    /// Recursively processes the JSON, detecting FormattedValue objects
    /// (objects with `raw` key and optionally `fmt`/`longFmt`) and
    /// transforming them according to the format setting.
    ///
    /// # Example
    ///
    /// ```
    /// use finance_query::ValueFormat;
    /// use serde_json::json;
    ///
    /// let data = json!({"price": {"raw": 123.45, "fmt": "$123.45"}});
    ///
    /// // Raw format extracts just the raw value (default)
    /// let raw = ValueFormat::default().transform(data.clone());
    /// assert_eq!(raw, json!({"price": 123.45}));
    ///
    /// // Pretty extracts just the formatted string
    /// let pretty = ValueFormat::Pretty.transform(data.clone());
    /// assert_eq!(pretty, json!({"price": "$123.45"}));
    ///
    /// // Both keeps the full object
    /// let both = ValueFormat::Both.transform(data);
    /// assert_eq!(both, json!({"price": {"raw": 123.45, "fmt": "$123.45"}}));
    /// ```
    pub fn transform(&self, value: serde_json::Value) -> serde_json::Value {
        match self {
            ValueFormat::Both => value, // No transformation needed
            _ => self.transform_recursive(value),
        }
    }

    fn transform_recursive(&self, value: serde_json::Value) -> serde_json::Value {
        use serde_json::Value;

        match value {
            Value::Object(map) => {
                // Check if this looks like a FormattedValue (has 'raw' key)
                if self.is_formatted_value(&map) {
                    return self.extract_value(&map);
                }

                // Otherwise, recursively transform all values
                let transformed: serde_json::Map<String, Value> = map
                    .into_iter()
                    .map(|(k, v)| (k, self.transform_recursive(v)))
                    .collect();
                Value::Object(transformed)
            }
            Value::Array(arr) => Value::Array(
                arr.into_iter()
                    .map(|v| self.transform_recursive(v))
                    .collect(),
            ),
            // Primitives pass through unchanged
            other => other,
        }
    }

    /// Check if an object looks like a FormattedValue
    fn is_formatted_value(&self, map: &serde_json::Map<String, serde_json::Value>) -> bool {
        // Must have 'raw' key (can be null)
        // May have 'fmt' and/or 'longFmt'
        // Should not have many other keys (FormattedValue only has these 3)
        if !map.contains_key("raw") {
            return false;
        }

        let known_keys = ["raw", "fmt", "longFmt"];
        let unknown_keys = map
            .keys()
            .filter(|k| !known_keys.contains(&k.as_str()))
            .count();

        // If there are unknown keys, it's probably not a FormattedValue
        unknown_keys == 0
    }

    /// Extract the appropriate value based on format
    fn extract_value(&self, map: &serde_json::Map<String, serde_json::Value>) -> serde_json::Value {
        match self {
            ValueFormat::Raw => {
                // Return raw value directly (or null if not present)
                map.get("raw").cloned().unwrap_or(serde_json::Value::Null)
            }
            ValueFormat::Pretty => {
                // Prefer fmt, fall back to longFmt, then null
                map.get("fmt")
                    .or_else(|| map.get("longFmt"))
                    .cloned()
                    .unwrap_or(serde_json::Value::Null)
            }
            ValueFormat::Both => {
                // Keep as-is (shouldn't reach here, but handle anyway)
                serde_json::Value::Object(map.clone())
            }
        }
    }
}

/// Typed industry identifiers shared between the industry endpoint and screener queries.
///
/// Use with [`finance::industry()`](crate::finance::industry) for the data endpoint, and with
/// [`EquityField::Industry`](crate::EquityField::Industry) +
/// [`ScreenerFieldExt::eq_str`](crate::ScreenerFieldExt::eq_str) for screener filtering.
///
/// - `as_slug()` → lowercase hyphenated key for `finance::industry()` (e.g. `"semiconductors"`)
/// - `From<Industry> for String` → screener display name (e.g. `"Semiconductors"`)
///
/// # Example
///
/// ```no_run
/// use finance_query::{finance, Industry, EquityField, EquityScreenerQuery, ScreenerFieldExt};
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// // Industry endpoint
/// let data = finance::industry(Industry::Semiconductors).await?;
///
/// // Screener filter
/// let query = EquityScreenerQuery::new()
///     .add_condition(EquityField::Industry.eq_str(Industry::Semiconductors));
/// # Ok(())
/// # }
/// ```
pub mod industries {
    /// Typed industry identifier for the industry endpoint and custom screener queries.
    ///
    /// See the module-level doc for usage.
    #[non_exhaustive]
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub enum Industry {
        // ── Agriculture / Raw Materials ──────────────────────────────────────
        /// Agricultural inputs, fertilizers, and crop chemicals
        AgriculturalInputs,
        /// Aluminum production and processing companies
        Aluminum,
        /// Coal mining and processing companies
        Coal,
        /// Copper mining and processing companies
        Copper,
        /// Farm products including grains, livestock, and produce
        FarmProducts,
        /// Forest products including timber and paper pulp
        ForestProducts,
        /// Gold mining and royalty companies
        Gold,
        /// Lumber and wood production companies
        LumberAndWoodProduction,
        /// Other industrial metals and mining (zinc, nickel, etc.)
        OtherIndustrialMetalsAndMining,
        /// Other precious metals and mining (platinum, palladium, etc.)
        OtherPreciousMetalsAndMining,
        /// Silver mining and streaming companies
        Silver,
        /// Steel production and processing companies
        Steel,
        /// Thermal coal mining for electricity generation
        ThermalCoal,
        /// Uranium mining companies
        Uranium,
        // ── Consumer ─────────────────────────────────────────────────────────
        /// Clothing and apparel manufacturing companies
        ApparelManufacturing,
        /// Clothing and apparel retail chains
        ApparelRetail,
        /// Automotive and truck dealerships
        AutoAndTruckDealerships,
        /// Automobile manufacturers and assemblers
        AutoManufacturers,
        /// Automotive parts manufacturers and distributors
        AutoParts,
        /// Beer brewing and distribution companies
        BeveragesBrewers,
        /// Non-alcoholic beverages including soft drinks and juices
        BeveragesNonAlcoholic,
        /// Wineries, distilleries, and spirits producers
        BeveragesWineriesAndDistilleries,
        /// Candy, chocolate, and confectionery makers
        Confectioners,
        /// Traditional department store retailers
        DepartmentStores,
        /// Discount and value retail stores
        DiscountStores,
        /// Electronic gaming software and multimedia entertainment
        ElectronicGamingAndMultimedia,
        /// Wholesale food distribution companies
        FoodDistribution,
        /// Footwear, handbags, and fashion accessories
        FootwearAndAccessories,
        /// Furniture, fixtures, and household appliances
        FurnishingsFixturesAndAppliances,
        /// Casinos, online gambling, and gaming operators
        Gambling,
        /// Supermarkets and grocery retail chains
        GroceryStores,
        /// Home improvement retail stores
        HomeImprovementRetail,
        /// Household cleaning products and personal care items
        HouseholdAndPersonalProducts,
        /// Online retail and e-commerce marketplaces
        InternetRetail,
        /// Leisure, recreation, and entertainment companies
        Leisure,
        /// Hotels and lodging companies
        Lodging,
        /// Luxury goods, fashion, and premium consumer brands
        LuxuryGoods,
        /// Packaged and processed food manufacturers
        PackagedFoods,
        /// Personal care, laundry, and household services
        PersonalServices,
        /// Home builders and residential construction
        ResidentialConstruction,
        /// Resorts, integrated casinos, and hotel-casinos
        ResortsAndCasinos,
        /// Restaurant chains and food service operators
        Restaurants,
        /// Specialty retail stores (pets, books, electronics, etc.)
        SpecialtyRetail,
        /// Textile and fabric manufacturers
        TextileManufacturing,
        /// Tobacco product manufacturers
        Tobacco,
        /// Travel agencies, booking platforms, and tour operators
        TravelServices,
        // ── Energy ───────────────────────────────────────────────────────────
        /// Oil and gas contract drilling services
        OilAndGasDrilling,
        /// Oil and gas exploration and production companies
        OilAndGasEAndP,
        /// Oil field equipment, services, and engineering
        OilAndGasEquipmentAndServices,
        /// Vertically integrated oil and gas majors
        OilAndGasIntegrated,
        /// Oil and gas pipelines, storage, and transportation
        OilAndGasMidstream,
        /// Oil refining, wholesale fuel, and marketing
        OilAndGasRefiningAndMarketing,
        /// Solar panel manufacturers and solar energy producers
        Solar,
        // ── Financial Services ───────────────────────────────────────────────
        /// Asset managers, fund sponsors, and investment advisors
        AssetManagement,
        /// Large diversified national and international banks
        BanksDiversified,
        /// Regional and community banks
        BanksRegional,
        /// Investment banks, brokers, and financial exchanges
        CapitalMarkets,
        /// Credit card issuers and consumer credit services
        CreditServices,
        /// Financial data, analytics, and stock exchange operators
        FinancialDataAndStockExchanges,
        /// Insurance brokers and agencies
        InsuranceBrokers,
        /// Diversified multi-line insurance companies
        InsuranceDiversified,
        /// Life insurance and annuity providers
        InsuranceLife,
        /// Property and casualty insurance companies
        InsurancePropertyAndCasualty,
        /// Reinsurance companies
        InsuranceReinsurance,
        /// Specialty insurance lines (title, mortgage, etc.)
        InsuranceSpecialty,
        /// Mortgage banking and loan origination
        MortgageFinance,
        /// Blank-check and shell holding companies
        ShellCompanies,
        // ── Healthcare ───────────────────────────────────────────────────────
        /// Biotechnology drug development companies
        Biotechnology,
        /// Medical diagnostics labs and clinical research
        DiagnosticsAndResearch,
        /// Large branded pharmaceutical manufacturers
        DrugManufacturersGeneral,
        /// Specialty drugs, generics, and biosimilars
        DrugManufacturersSpecialtyAndGeneric,
        /// Healthcare IT, EHR, and health data services
        HealthInformationServices,
        /// Managed care organizations and health insurers
        HealthcarePlans,
        /// Hospitals, clinics, and outpatient care facilities
        MedicalCareFacilities,
        /// Medical device manufacturers (implants, diagnostics equipment)
        MedicalDevices,
        /// Medical product wholesalers and distributors
        MedicalDistribution,
        /// Surgical instruments, disposables, and medical supplies
        MedicalInstrumentsAndSupplies,
        /// Retail pharmacies and drug store chains
        PharmaceuticalRetailers,
        // ── Industrials ──────────────────────────────────────────────────────
        /// Defense contractors, aircraft, and space systems
        AerospaceAndDefense,
        /// Construction aggregates, cement, and building materials
        BuildingMaterials,
        /// HVAC, plumbing, windows, and building equipment
        BuildingProductsAndEquipment,
        /// Office supplies, commercial equipment, and printers
        BusinessEquipmentAndSupplies,
        /// Specialty chemical manufacturing for industrial use
        ChemicalManufacturing,
        /// Diversified commodity chemicals producers
        Chemicals,
        /// Diversified industrial holding companies
        Conglomerates,
        /// Management consulting and professional advisory services
        ConsultingServices,
        /// Electrical components, motors, and power equipment
        ElectricalEquipmentAndParts,
        /// Civil engineering, construction, and infrastructure projects
        EngineeringAndConstruction,
        /// Agricultural equipment and heavy construction machinery
        FarmAndHeavyConstructionMachinery,
        /// Industrial goods wholesalers and distributors
        IndustrialDistribution,
        /// Toll roads, airports, and infrastructure operators
        InfrastructureOperations,
        /// Third-party logistics and supply chain management
        IntegratedFreightAndLogistics,
        /// Diversified manufacturers across multiple industrial segments
        ManufacturingDiversified,
        /// Port operators and marine terminal services
        MarinePortsAndServices,
        /// Bulk cargo and tanker shipping companies
        MarineShipping,
        /// Custom metal fabrication and machined components
        MetalFabrication,
        /// Paper, packaging, and pulp product manufacturers
        PaperAndPaperProducts,
        /// Environmental controls, water treatment, and remediation
        PollutionAndTreatmentControls,
        /// Rail freight carriers and passenger rail operators
        Railroads,
        /// Equipment rental, leasing, and fleet management
        RentalAndLeasingServices,
        /// Security systems, guards, and monitoring services
        SecurityAndProtectionServices,
        /// Outsourced business services and BPO companies
        SpecialtyBusinessServices,
        /// High-value specialty chemicals and advanced materials
        SpecialtyChemicals,
        /// Specialized industrial machinery and equipment makers
        SpecialtyIndustrialMachinery,
        /// Staffing agencies and employment service providers
        StaffingAndEmploymentServices,
        /// Hand tools, power tools, and hardware accessories
        ToolsAndAccessories,
        /// Freight trucking and less-than-truckload carriers
        Trucking,
        /// Waste collection, recycling, and disposal services
        WasteManagement,
        // ── Real Estate ──────────────────────────────────────────────────────
        /// Real estate developers and homebuilders
        RealEstateDevelopment,
        /// Diversified real estate companies with mixed portfolios
        RealEstateDiversified,
        /// Real estate brokers, agents, and property managers
        RealEstateServices,
        /// Diversified REITs across multiple property types
        ReitDiversified,
        /// Healthcare and senior living facility REITs
        ReitHealthcareFacilities,
        /// Hotel and motel property REITs
        ReitHotelAndMotel,
        /// Industrial, warehouse, and logistics property REITs
        ReitIndustrial,
        /// Mortgage REITs investing in real estate debt
        ReitMortgage,
        /// Office building and commercial property REITs
        ReitOffice,
        /// Apartment, multifamily, and residential property REITs
        ReitResidential,
        /// Shopping center and retail property REITs
        ReitRetail,
        /// Specialty REITs (data centers, cell towers, self-storage)
        ReitSpecialty,
        // ── Technology ───────────────────────────────────────────────────────
        /// Networking hardware, routers, and communication equipment
        CommunicationEquipment,
        /// PCs, servers, and computer hardware manufacturers
        ComputerHardware,
        /// Smartphones, TVs, and consumer electronic devices
        ConsumerElectronics,
        /// Data analytics, business intelligence, and AI platforms
        DataAnalytics,
        /// Passive electronic components and circuit boards
        ElectronicComponents,
        /// Distributors of electronics and computer products
        ElectronicsAndComputerDistribution,
        /// Value-added resellers and software/hardware distributors
        HardwareAndSoftwareDistribution,
        /// IT services, outsourcing, and technology consulting
        InformationTechnologyServices,
        /// Online media, search engines, and digital content platforms
        InternetContentAndInformation,
        /// Precision instruments, sensors, and test equipment
        ScientificAndTechnicalInstruments,
        /// Semiconductor manufacturing equipment and materials
        SemiconductorEquipmentAndMaterials,
        /// Integrated circuit and chip designers and manufacturers
        Semiconductors,
        /// Business application software companies
        SoftwareApplication,
        /// Operating systems, middleware, and infrastructure software
        SoftwareInfrastructure,
        // ── Communication Services ───────────────────────────────────────────
        /// Television, radio, and broadcast media companies
        Broadcasting,
        /// Film studios, streaming, and live entertainment
        Entertainment,
        /// Book, magazine, newspaper, and digital media publishers
        Publishing,
        /// Wireless carriers and wireline telephone companies
        TelecomServices,
        // ── Utilities ────────────────────────────────────────────────────────
        /// Multi-utility companies serving electricity, gas, and water
        UtilitiesDiversified,
        /// Independent power producers and energy traders
        UtilitiesIndependentPowerProducers,
        /// Regulated electric utility companies
        UtilitiesRegulatedElectric,
        /// Regulated natural gas distribution utilities
        UtilitiesRegulatedGas,
        /// Regulated water and wastewater utilities
        UtilitiesRegulatedWater,
        /// Renewable energy generation companies (wind, solar, hydro)
        UtilitiesRenewable,
        // ── Special ──────────────────────────────────────────────────────────
        /// Closed-end funds investing in debt instruments
        ClosedEndFundDebt,
        /// Closed-end funds investing in equities
        ClosedEndFundEquity,
        /// Closed-end funds investing in foreign securities
        ClosedEndFundForeign,
        /// Exchange-traded fund products
        ExchangeTradedFund,
    }

    impl Industry {
        /// Returns the lowercase hyphenated slug used by `finance::industry()`.
        ///
        /// # Example
        ///
        /// ```
        /// use finance_query::Industry;
        /// assert_eq!(Industry::Semiconductors.as_slug(), "semiconductors");
        /// assert_eq!(Industry::SoftwareApplication.as_slug(), "software-application");
        /// ```
        pub fn as_slug(self) -> &'static str {
            match self {
                Industry::AgriculturalInputs => "agricultural-inputs",
                Industry::Aluminum => "aluminum",
                Industry::Coal => "coal",
                Industry::Copper => "copper",
                Industry::FarmProducts => "farm-products",
                Industry::ForestProducts => "forest-products",
                Industry::Gold => "gold",
                Industry::LumberAndWoodProduction => "lumber-wood-production",
                Industry::OtherIndustrialMetalsAndMining => "other-industrial-metals-mining",
                Industry::OtherPreciousMetalsAndMining => "other-precious-metals-mining",
                Industry::Silver => "silver",
                Industry::Steel => "steel",
                Industry::ThermalCoal => "thermal-coal",
                Industry::Uranium => "uranium",
                Industry::ApparelManufacturing => "apparel-manufacturing",
                Industry::ApparelRetail => "apparel-retail",
                Industry::AutoAndTruckDealerships => "auto-truck-dealerships",
                Industry::AutoManufacturers => "auto-manufacturers",
                Industry::AutoParts => "auto-parts",
                Industry::BeveragesBrewers => "beverages-brewers",
                Industry::BeveragesNonAlcoholic => "beverages-non-alcoholic",
                Industry::BeveragesWineriesAndDistilleries => "beverages-wineries-distilleries",
                Industry::Confectioners => "confectioners",
                Industry::DepartmentStores => "department-stores",
                Industry::DiscountStores => "discount-stores",
                Industry::ElectronicGamingAndMultimedia => "electronic-gaming-multimedia",
                Industry::FoodDistribution => "food-distribution",
                Industry::FootwearAndAccessories => "footwear-accessories",
                Industry::FurnishingsFixturesAndAppliances => "furnishings-fixtures-appliances",
                Industry::Gambling => "gambling",
                Industry::GroceryStores => "grocery-stores",
                Industry::HomeImprovementRetail => "home-improvement-retail",
                Industry::HouseholdAndPersonalProducts => "household-personal-products",
                Industry::InternetRetail => "internet-retail",
                Industry::Leisure => "leisure",
                Industry::Lodging => "lodging",
                Industry::LuxuryGoods => "luxury-goods",
                Industry::PackagedFoods => "packaged-foods",
                Industry::PersonalServices => "personal-services",
                Industry::ResidentialConstruction => "residential-construction",
                Industry::ResortsAndCasinos => "resorts-casinos",
                Industry::Restaurants => "restaurants",
                Industry::SpecialtyRetail => "specialty-retail",
                Industry::TextileManufacturing => "textile-manufacturing",
                Industry::Tobacco => "tobacco",
                Industry::TravelServices => "travel-services",
                Industry::OilAndGasDrilling => "oil-gas-drilling",
                Industry::OilAndGasEAndP => "oil-gas-ep",
                Industry::OilAndGasEquipmentAndServices => "oil-gas-equipment-services",
                Industry::OilAndGasIntegrated => "oil-gas-integrated",
                Industry::OilAndGasMidstream => "oil-gas-midstream",
                Industry::OilAndGasRefiningAndMarketing => "oil-gas-refining-marketing",
                Industry::Solar => "solar",
                Industry::AssetManagement => "asset-management",
                Industry::BanksDiversified => "banks-diversified",
                Industry::BanksRegional => "banks-regional",
                Industry::CapitalMarkets => "capital-markets",
                Industry::CreditServices => "credit-services",
                Industry::FinancialDataAndStockExchanges => "financial-data-stock-exchanges",
                Industry::InsuranceBrokers => "insurance-brokers",
                Industry::InsuranceDiversified => "insurance-diversified",
                Industry::InsuranceLife => "insurance-life",
                Industry::InsurancePropertyAndCasualty => "insurance-property-casualty",
                Industry::InsuranceReinsurance => "insurance-reinsurance",
                Industry::InsuranceSpecialty => "insurance-specialty",
                Industry::MortgageFinance => "mortgage-finance",
                Industry::ShellCompanies => "shell-companies",
                Industry::Biotechnology => "biotechnology",
                Industry::DiagnosticsAndResearch => "diagnostics-research",
                Industry::DrugManufacturersGeneral => "drug-manufacturers-general",
                Industry::DrugManufacturersSpecialtyAndGeneric => {
                    "drug-manufacturers-specialty-generic"
                }
                Industry::HealthInformationServices => "health-information-services",
                Industry::HealthcarePlans => "healthcare-plans",
                Industry::MedicalCareFacilities => "medical-care-facilities",
                Industry::MedicalDevices => "medical-devices",
                Industry::MedicalDistribution => "medical-distribution",
                Industry::MedicalInstrumentsAndSupplies => "medical-instruments-supplies",
                Industry::PharmaceuticalRetailers => "pharmaceutical-retailers",
                Industry::AerospaceAndDefense => "aerospace-defense",
                Industry::BuildingMaterials => "building-materials",
                Industry::BuildingProductsAndEquipment => "building-products-equipment",
                Industry::BusinessEquipmentAndSupplies => "business-equipment-supplies",
                Industry::ChemicalManufacturing => "chemical-manufacturing",
                Industry::Chemicals => "chemicals",
                Industry::Conglomerates => "conglomerates",
                Industry::ConsultingServices => "consulting-services",
                Industry::ElectricalEquipmentAndParts => "electrical-equipment-parts",
                Industry::EngineeringAndConstruction => "engineering-construction",
                Industry::FarmAndHeavyConstructionMachinery => "farm-heavy-construction-machinery",
                Industry::IndustrialDistribution => "industrial-distribution",
                Industry::InfrastructureOperations => "infrastructure-operations",
                Industry::IntegratedFreightAndLogistics => "integrated-freight-logistics",
                Industry::ManufacturingDiversified => "manufacturing-diversified",
                Industry::MarinePortsAndServices => "marine-ports-services",
                Industry::MarineShipping => "marine-shipping",
                Industry::MetalFabrication => "metal-fabrication",
                Industry::PaperAndPaperProducts => "paper-paper-products",
                Industry::PollutionAndTreatmentControls => "pollution-treatment-controls",
                Industry::Railroads => "railroads",
                Industry::RentalAndLeasingServices => "rental-leasing-services",
                Industry::SecurityAndProtectionServices => "security-protection-services",
                Industry::SpecialtyBusinessServices => "specialty-business-services",
                Industry::SpecialtyChemicals => "specialty-chemicals",
                Industry::SpecialtyIndustrialMachinery => "specialty-industrial-machinery",
                Industry::StaffingAndEmploymentServices => "staffing-employment-services",
                Industry::ToolsAndAccessories => "tools-accessories",
                Industry::Trucking => "trucking",
                Industry::WasteManagement => "waste-management",
                Industry::RealEstateDevelopment => "real-estate-development",
                Industry::RealEstateDiversified => "real-estate-diversified",
                Industry::RealEstateServices => "real-estate-services",
                Industry::ReitDiversified => "reit-diversified",
                Industry::ReitHealthcareFacilities => "reit-healthcare-facilities",
                Industry::ReitHotelAndMotel => "reit-hotel-motel",
                Industry::ReitIndustrial => "reit-industrial",
                Industry::ReitMortgage => "reit-mortgage",
                Industry::ReitOffice => "reit-office",
                Industry::ReitResidential => "reit-residential",
                Industry::ReitRetail => "reit-retail",
                Industry::ReitSpecialty => "reit-specialty",
                Industry::CommunicationEquipment => "communication-equipment",
                Industry::ComputerHardware => "computer-hardware",
                Industry::ConsumerElectronics => "consumer-electronics",
                Industry::DataAnalytics => "data-analytics",
                Industry::ElectronicComponents => "electronic-components",
                Industry::ElectronicsAndComputerDistribution => "electronics-computer-distribution",
                Industry::HardwareAndSoftwareDistribution => "hardware-software-distribution",
                Industry::InformationTechnologyServices => "information-technology-services",
                Industry::InternetContentAndInformation => "internet-content-information",
                Industry::ScientificAndTechnicalInstruments => "scientific-technical-instruments",
                Industry::SemiconductorEquipmentAndMaterials => "semiconductor-equipment-materials",
                Industry::Semiconductors => "semiconductors",
                Industry::SoftwareApplication => "software-application",
                Industry::SoftwareInfrastructure => "software-infrastructure",
                Industry::Broadcasting => "broadcasting",
                Industry::Entertainment => "entertainment",
                Industry::Publishing => "publishing",
                Industry::TelecomServices => "telecom-services",
                Industry::UtilitiesDiversified => "utilities-diversified",
                Industry::UtilitiesIndependentPowerProducers => {
                    "utilities-independent-power-producers"
                }
                Industry::UtilitiesRegulatedElectric => "utilities-regulated-electric",
                Industry::UtilitiesRegulatedGas => "utilities-regulated-gas",
                Industry::UtilitiesRegulatedWater => "utilities-regulated-water",
                Industry::UtilitiesRenewable => "utilities-renewable",
                Industry::ClosedEndFundDebt => "closed-end-fund-debt",
                Industry::ClosedEndFundEquity => "closed-end-fund-equity",
                Industry::ClosedEndFundForeign => "closed-end-fund-foreign",
                Industry::ExchangeTradedFund => "exchange-traded-fund",
            }
        }

        /// Returns the display name used by the Yahoo Finance screener.
        ///
        /// # Example
        ///
        /// ```
        /// use finance_query::Industry;
        /// assert_eq!(Industry::Semiconductors.screener_value(), "Semiconductors");
        /// assert_eq!(Industry::OilAndGasDrilling.screener_value(), "Oil & Gas Drilling");
        /// ```
        pub fn screener_value(self) -> &'static str {
            match self {
                Industry::AgriculturalInputs => "Agricultural Inputs",
                Industry::Aluminum => "Aluminum",
                Industry::Coal => "Coal",
                Industry::Copper => "Copper",
                Industry::FarmProducts => "Farm Products",
                Industry::ForestProducts => "Forest Products",
                Industry::Gold => "Gold",
                Industry::LumberAndWoodProduction => "Lumber & Wood Production",
                Industry::OtherIndustrialMetalsAndMining => "Other Industrial Metals & Mining",
                Industry::OtherPreciousMetalsAndMining => "Other Precious Metals & Mining",
                Industry::Silver => "Silver",
                Industry::Steel => "Steel",
                Industry::ThermalCoal => "Thermal Coal",
                Industry::Uranium => "Uranium",
                Industry::ApparelManufacturing => "Apparel Manufacturing",
                Industry::ApparelRetail => "Apparel Retail",
                Industry::AutoAndTruckDealerships => "Auto & Truck Dealerships",
                Industry::AutoManufacturers => "Auto Manufacturers",
                Industry::AutoParts => "Auto Parts",
                Industry::BeveragesBrewers => "Beverages - Brewers",
                Industry::BeveragesNonAlcoholic => "Beverages - Non-Alcoholic",
                Industry::BeveragesWineriesAndDistilleries => "Beverages - Wineries & Distilleries",
                Industry::Confectioners => "Confectioners",
                Industry::DepartmentStores => "Department Stores",
                Industry::DiscountStores => "Discount Stores",
                Industry::ElectronicGamingAndMultimedia => "Electronic Gaming & Multimedia",
                Industry::FoodDistribution => "Food Distribution",
                Industry::FootwearAndAccessories => "Footwear & Accessories",
                Industry::FurnishingsFixturesAndAppliances => "Furnishings, Fixtures & Appliances",
                Industry::Gambling => "Gambling",
                Industry::GroceryStores => "Grocery Stores",
                Industry::HomeImprovementRetail => "Home Improvement Retail",
                Industry::HouseholdAndPersonalProducts => "Household & Personal Products",
                Industry::InternetRetail => "Internet Retail",
                Industry::Leisure => "Leisure",
                Industry::Lodging => "Lodging",
                Industry::LuxuryGoods => "Luxury Goods",
                Industry::PackagedFoods => "Packaged Foods",
                Industry::PersonalServices => "Personal Services",
                Industry::ResidentialConstruction => "Residential Construction",
                Industry::ResortsAndCasinos => "Resorts & Casinos",
                Industry::Restaurants => "Restaurants",
                Industry::SpecialtyRetail => "Specialty Retail",
                Industry::TextileManufacturing => "Textile Manufacturing",
                Industry::Tobacco => "Tobacco",
                Industry::TravelServices => "Travel Services",
                Industry::OilAndGasDrilling => "Oil & Gas Drilling",
                Industry::OilAndGasEAndP => "Oil & Gas E&P",
                Industry::OilAndGasEquipmentAndServices => "Oil & Gas Equipment & Services",
                Industry::OilAndGasIntegrated => "Oil & Gas Integrated",
                Industry::OilAndGasMidstream => "Oil & Gas Midstream",
                Industry::OilAndGasRefiningAndMarketing => "Oil & Gas Refining & Marketing",
                Industry::Solar => "Solar",
                Industry::AssetManagement => "Asset Management",
                Industry::BanksDiversified => "Banks - Diversified",
                Industry::BanksRegional => "Banks - Regional",
                Industry::CapitalMarkets => "Capital Markets",
                Industry::CreditServices => "Credit Services",
                Industry::FinancialDataAndStockExchanges => "Financial Data & Stock Exchanges",
                Industry::InsuranceBrokers => "Insurance Brokers",
                Industry::InsuranceDiversified => "Insurance - Diversified",
                Industry::InsuranceLife => "Insurance - Life",
                Industry::InsurancePropertyAndCasualty => "Insurance - Property & Casualty",
                Industry::InsuranceReinsurance => "Insurance - Reinsurance",
                Industry::InsuranceSpecialty => "Insurance - Specialty",
                Industry::MortgageFinance => "Mortgage Finance",
                Industry::ShellCompanies => "Shell Companies",
                Industry::Biotechnology => "Biotechnology",
                Industry::DiagnosticsAndResearch => "Diagnostics & Research",
                Industry::DrugManufacturersGeneral => "Drug Manufacturers - General",
                Industry::DrugManufacturersSpecialtyAndGeneric => {
                    "Drug Manufacturers - Specialty & Generic"
                }
                Industry::HealthInformationServices => "Health Information Services",
                Industry::HealthcarePlans => "Healthcare Plans",
                Industry::MedicalCareFacilities => "Medical Care Facilities",
                Industry::MedicalDevices => "Medical Devices",
                Industry::MedicalDistribution => "Medical Distribution",
                Industry::MedicalInstrumentsAndSupplies => "Medical Instruments & Supplies",
                Industry::PharmaceuticalRetailers => "Pharmaceutical Retailers",
                Industry::AerospaceAndDefense => "Aerospace & Defense",
                Industry::BuildingMaterials => "Building Materials",
                Industry::BuildingProductsAndEquipment => "Building Products & Equipment",
                Industry::BusinessEquipmentAndSupplies => "Business Equipment & Supplies",
                Industry::ChemicalManufacturing => "Chemical Manufacturing",
                Industry::Chemicals => "Chemicals",
                Industry::Conglomerates => "Conglomerates",
                Industry::ConsultingServices => "Consulting Services",
                Industry::ElectricalEquipmentAndParts => "Electrical Equipment & Parts",
                Industry::EngineeringAndConstruction => "Engineering & Construction",
                Industry::FarmAndHeavyConstructionMachinery => {
                    "Farm & Heavy Construction Machinery"
                }
                Industry::IndustrialDistribution => "Industrial Distribution",
                Industry::InfrastructureOperations => "Infrastructure Operations",
                Industry::IntegratedFreightAndLogistics => "Integrated Freight & Logistics",
                Industry::ManufacturingDiversified => "Manufacturing - Diversified",
                Industry::MarinePortsAndServices => "Marine Ports & Services",
                Industry::MarineShipping => "Marine Shipping",
                Industry::MetalFabrication => "Metal Fabrication",
                Industry::PaperAndPaperProducts => "Paper & Paper Products",
                Industry::PollutionAndTreatmentControls => "Pollution & Treatment Controls",
                Industry::Railroads => "Railroads",
                Industry::RentalAndLeasingServices => "Rental & Leasing Services",
                Industry::SecurityAndProtectionServices => "Security & Protection Services",
                Industry::SpecialtyBusinessServices => "Specialty Business Services",
                Industry::SpecialtyChemicals => "Specialty Chemicals",
                Industry::SpecialtyIndustrialMachinery => "Specialty Industrial Machinery",
                Industry::StaffingAndEmploymentServices => "Staffing & Employment Services",
                Industry::ToolsAndAccessories => "Tools & Accessories",
                Industry::Trucking => "Trucking",
                Industry::WasteManagement => "Waste Management",
                Industry::RealEstateDevelopment => "Real Estate - Development",
                Industry::RealEstateDiversified => "Real Estate - Diversified",
                Industry::RealEstateServices => "Real Estate Services",
                Industry::ReitDiversified => "REIT - Diversified",
                Industry::ReitHealthcareFacilities => "REIT - Healthcare Facilities",
                Industry::ReitHotelAndMotel => "REIT - Hotel & Motel",
                Industry::ReitIndustrial => "REIT - Industrial",
                Industry::ReitMortgage => "REIT - Mortgage",
                Industry::ReitOffice => "REIT - Office",
                Industry::ReitResidential => "REIT - Residential",
                Industry::ReitRetail => "REIT - Retail",
                Industry::ReitSpecialty => "REIT - Specialty",
                Industry::CommunicationEquipment => "Communication Equipment",
                Industry::ComputerHardware => "Computer Hardware",
                Industry::ConsumerElectronics => "Consumer Electronics",
                Industry::DataAnalytics => "Data Analytics",
                Industry::ElectronicComponents => "Electronic Components",
                Industry::ElectronicsAndComputerDistribution => {
                    "Electronics & Computer Distribution"
                }
                Industry::HardwareAndSoftwareDistribution => "Hardware & Software Distribution",
                Industry::InformationTechnologyServices => "Information Technology Services",
                Industry::InternetContentAndInformation => "Internet Content & Information",
                Industry::ScientificAndTechnicalInstruments => "Scientific & Technical Instruments",
                Industry::SemiconductorEquipmentAndMaterials => {
                    "Semiconductor Equipment & Materials"
                }
                Industry::Semiconductors => "Semiconductors",
                Industry::SoftwareApplication => "Software - Application",
                Industry::SoftwareInfrastructure => "Software - Infrastructure",
                Industry::Broadcasting => "Broadcasting",
                Industry::Entertainment => "Entertainment",
                Industry::Publishing => "Publishing",
                Industry::TelecomServices => "Telecom Services",
                Industry::UtilitiesDiversified => "Utilities - Diversified",
                Industry::UtilitiesIndependentPowerProducers => {
                    "Utilities - Independent Power Producers"
                }
                Industry::UtilitiesRegulatedElectric => "Utilities - Regulated Electric",
                Industry::UtilitiesRegulatedGas => "Utilities - Regulated Gas",
                Industry::UtilitiesRegulatedWater => "Utilities - Regulated Water",
                Industry::UtilitiesRenewable => "Utilities - Renewable",
                Industry::ClosedEndFundDebt => "Closed-End Fund - Debt",
                Industry::ClosedEndFundEquity => "Closed-End Fund - Equity",
                Industry::ClosedEndFundForeign => "Closed-End Fund - Foreign",
                Industry::ExchangeTradedFund => "Exchange Traded Fund",
            }
        }
    }

    impl AsRef<str> for Industry {
        /// Returns the slug, enabling `finance::industry(Industry::Semiconductors)`.
        fn as_ref(&self) -> &str {
            self.as_slug()
        }
    }

    impl From<Industry> for String {
        /// Returns the screener display name, enabling `EquityField::Industry.eq_str(Industry::Semiconductors)`.
        fn from(v: Industry) -> Self {
            v.screener_value().to_string()
        }
    }
}

/// Typed exchange codes for screener queries.
///
/// Use with [`EquityField::Exchange`](crate::EquityField::Exchange) or
/// [`FundField::Exchange`](crate::FundField::Exchange) and
/// [`ScreenerFieldExt::eq_str`](crate::ScreenerFieldExt::eq_str).
///
/// For mutual fund queries use [`ExchangeCode::Nas`].
///
/// # Example
///
/// ```
/// use finance_query::{EquityField, EquityScreenerQuery, ScreenerFieldExt, ExchangeCode};
///
/// let query = EquityScreenerQuery::new()
///     .add_condition(EquityField::Exchange.eq_str(ExchangeCode::Nms));
/// ```
pub mod exchange_codes {
    /// Typed exchange code for screener queries.
    #[non_exhaustive]
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub enum ExchangeCode {
        // ── US Equity ─────────────────────────────────────────────────────────
        /// NYSE American / AMEX ("ASE")
        Ase,
        /// OTC Bulletin Board ("BTS")
        Bts,
        /// NASDAQ Capital Market ("NCM")
        Ncm,
        /// NASDAQ Global Market ("NGM")
        Ngm,
        /// NASDAQ Global Select Market ("NMS") — primary NASDAQ tier
        Nms,
        /// New York Stock Exchange ("NYQ")
        Nyq,
        /// NYSE Arca ("PCX")
        Pcx,
        /// OTC Pink Sheets / OTC Markets ("PNK")
        Pnk,
        // ── US Funds ──────────────────────────────────────────────────────────
        /// NASDAQ — used for US mutual funds ("NAS")
        Nas,
        // ── International ─────────────────────────────────────────────────────
        /// Australian Securities Exchange ("ASX")
        Asx,
        /// Bombay Stock Exchange ("BSE")
        Bse,
        /// Hong Kong Stock Exchange ("HKG")
        Hkg,
        /// Korea Exchange ("KRX")
        Krx,
        /// London Stock Exchange ("LSE")
        Lse,
        /// National Stock Exchange of India ("NSI")
        Nsi,
        /// Shanghai Stock Exchange ("SHH")
        Shh,
        /// Shenzhen Stock Exchange ("SHZ")
        Shz,
        /// Tokyo Stock Exchange ("TYO")
        Tyo,
        /// Toronto Stock Exchange ("TOR")
        Tor,
        /// XETRA / Deutsche Börse ("GER")
        Ger,
    }

    impl ExchangeCode {
        /// Returns the exchange code string used by Yahoo Finance.
        pub fn as_str(self) -> &'static str {
            match self {
                ExchangeCode::Ase => "ASE",
                ExchangeCode::Bts => "BTS",
                ExchangeCode::Ncm => "NCM",
                ExchangeCode::Ngm => "NGM",
                ExchangeCode::Nms => "NMS",
                ExchangeCode::Nyq => "NYQ",
                ExchangeCode::Pcx => "PCX",
                ExchangeCode::Pnk => "PNK",
                ExchangeCode::Nas => "NAS",
                ExchangeCode::Asx => "ASX",
                ExchangeCode::Bse => "BSE",
                ExchangeCode::Hkg => "HKG",
                ExchangeCode::Krx => "KRX",
                ExchangeCode::Lse => "LSE",
                ExchangeCode::Nsi => "NSI",
                ExchangeCode::Shh => "SHH",
                ExchangeCode::Shz => "SHZ",
                ExchangeCode::Tyo => "TYO",
                ExchangeCode::Tor => "TOR",
                ExchangeCode::Ger => "GER",
            }
        }
    }

    impl From<ExchangeCode> for String {
        fn from(v: ExchangeCode) -> Self {
            v.as_str().to_string()
        }
    }
}

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

    #[test]
    fn test_interval_as_str() {
        assert_eq!(Interval::OneMinute.as_str(), "1m");
        assert_eq!(Interval::FiveMinutes.as_str(), "5m");
        assert_eq!(Interval::OneDay.as_str(), "1d");
        assert_eq!(Interval::OneWeek.as_str(), "1wk");
    }

    #[test]
    fn test_time_range_as_str() {
        assert_eq!(TimeRange::OneDay.as_str(), "1d");
        assert_eq!(TimeRange::OneMonth.as_str(), "1mo");
        assert_eq!(TimeRange::OneYear.as_str(), "1y");
        assert_eq!(TimeRange::Max.as_str(), "max");
    }
}