libfmp 1.3.1

Async, typed Rust client for the Financial Modeling Prep API
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
//! SEC filing, company lookup, profile, and industry-classification query contracts.
//!
//! The provider documents every SEC-filings route as available for US-based
//! companies only, so each descriptor carries
//! [`GeographicAvailability::UsOnly`]. The Python binding exposes the same
//! twelve routes under `client.sec_filings`.

use crate::{
    Client, Result,
    codecs::DynamicObject,
    endpoints::{
        EndpointSpec, QueryEncoder, QueryParameters,
        metadata::{EndpointBounds, EndpointMetadata, GeographicAvailability},
    },
    responses::sec_filings::{
        SecCompanyProfile, SecCompanySearchResult, SecFiling, SicClassification,
    },
    types::{Cik, Date, FormType, Limit, Page, SearchTerm, Ticker},
};

macro_rules! date_page_limit_query {
    ($name:ident, $description:literal) => {
        #[doc = $description]
        #[derive(Debug, Clone, PartialEq, Eq)]
        pub struct $name {
            from: Date,
            to: Date,
            page: Option<Page>,
            limit: Option<Limit>,
        }

        impl $name {
            /// Creates a query without undocumented pagination defaults.
            pub const fn new(from: Date, to: Date) -> Self {
                Self {
                    from,
                    to,
                    page: None,
                    limit: None,
                }
            }

            /// Sets the optional provider page index.
            pub const fn with_page(mut self, page: Page) -> Self {
                self.page = Some(page);
                self
            }

            /// Sets the optional provider result limit.
            pub const fn with_limit(mut self, limit: Limit) -> Self {
                self.limit = Some(limit);
                self
            }

            /// Returns the required inclusive start date.
            pub const fn from(&self) -> Date {
                self.from
            }

            /// Returns the required inclusive end date.
            pub const fn to(&self) -> Date {
                self.to
            }

            /// Returns the optional provider page index.
            pub const fn page(&self) -> Option<Page> {
                self.page
            }

            /// Returns the optional provider result limit.
            pub const fn limit(&self) -> Option<Limit> {
                self.limit
            }
        }

        impl QueryParameters for $name {
            fn encode(&self, encoder: &mut QueryEncoder<'_>) {
                encoder.required("from", self.from);
                encoder.required("to", self.to);
                encoder.optional("page", self.page);
                encoder.optional("limit", self.limit);
            }
        }
    };
}

date_page_limit_query!(
    Latest8kSecFilingsQuery,
    "Required date bounds and optional pagination for the latest US 8-K filings."
);
date_page_limit_query!(
    LatestSecFilingsQuery,
    "Required date bounds and optional pagination for the latest US financial filings."
);

macro_rules! filing_search_query {
    ($name:ident, $field:ident, $field_type:ty, $wire_key:literal, $description:literal) => {
        #[doc = $description]
        #[derive(Debug, Clone, PartialEq, Eq)]
        pub struct $name {
            $field: $field_type,
            from: Date,
            to: Date,
            page: Option<Page>,
            limit: Option<Limit>,
        }

        impl $name {
            /// Creates a filing search without undocumented pagination defaults.
            pub const fn new($field: $field_type, from: Date, to: Date) -> Self {
                Self {
                    $field,
                    from,
                    to,
                    page: None,
                    limit: None,
                }
            }

            /// Sets the optional provider page index.
            pub const fn with_page(mut self, page: Page) -> Self {
                self.page = Some(page);
                self
            }

            /// Sets the optional provider result limit.
            pub const fn with_limit(mut self, limit: Limit) -> Self {
                self.limit = Some(limit);
                self
            }

            /// Borrows the required filing-search key.
            pub const fn $field(&self) -> &$field_type {
                &self.$field
            }

            /// Returns the required inclusive start date.
            pub const fn from(&self) -> Date {
                self.from
            }

            /// Returns the required inclusive end date.
            pub const fn to(&self) -> Date {
                self.to
            }

            /// Returns the optional provider page index.
            pub const fn page(&self) -> Option<Page> {
                self.page
            }

            /// Returns the optional provider result limit.
            pub const fn limit(&self) -> Option<Limit> {
                self.limit
            }
        }

        impl QueryParameters for $name {
            fn encode(&self, encoder: &mut QueryEncoder<'_>) {
                encoder.required($wire_key, &self.$field);
                encoder.required("from", self.from);
                encoder.required("to", self.to);
                encoder.optional("page", self.page);
                encoder.optional("limit", self.limit);
            }
        }
    };
}

filing_search_query!(
    SecFilingsByFormTypeQuery,
    form_type,
    FormType,
    "formType",
    "Required form type and dates plus optional pagination for US SEC filings."
);
filing_search_query!(
    SecFilingsBySymbolQuery,
    symbol,
    Ticker,
    "symbol",
    "Required ticker and dates plus optional pagination for US SEC filings."
);
filing_search_query!(
    SecFilingsByCikQuery,
    cik,
    Cik,
    "cik",
    "Required CIK and dates plus optional pagination for US SEC filings."
);

macro_rules! required_search_query {
    ($name:ident, $field:ident, $field_type:ty, $wire_key:literal, $description:literal) => {
        #[doc = $description]
        #[derive(Debug, Clone, PartialEq, Eq)]
        pub struct $name {
            $field: $field_type,
        }

        impl $name {
            /// Creates a company lookup preserving the exact search value.
            pub const fn new($field: $field_type) -> Self {
                Self { $field }
            }

            /// Borrows the required lookup value.
            pub const fn $field(&self) -> &$field_type {
                &self.$field
            }
        }

        impl From<$field_type> for $name {
            fn from(value: $field_type) -> Self {
                Self::new(value)
            }
        }

        impl From<&$field_type> for $name {
            fn from(value: &$field_type) -> Self {
                Self::new(value.clone())
            }
        }

        impl QueryParameters for $name {
            fn encode(&self, encoder: &mut QueryEncoder<'_>) {
                encoder.required($wire_key, &self.$field);
            }
        }
    };
}

required_search_query!(
    SecCompaniesByNameQuery,
    company,
    SearchTerm,
    "company",
    "Required company-name text for a US SEC company lookup."
);
required_search_query!(
    SecCompaniesBySymbolQuery,
    symbol,
    Ticker,
    "symbol",
    "Required ticker for a US SEC company lookup."
);
required_search_query!(
    SecCompaniesByCikQuery,
    cik,
    Cik,
    "cik",
    "Required CIK for a US SEC company lookup."
);

/// Required ticker and optional literal `cik-A` value for a full SEC profile.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SecCompanyProfileQuery {
    symbol: Ticker,
    cik_a: Option<Cik>,
}

impl SecCompanyProfileQuery {
    /// Creates a profile query without an undocumented `cik-A` value.
    pub const fn new(symbol: Ticker) -> Self {
        Self {
            symbol,
            cik_a: None,
        }
    }

    /// Sets the provider's literal optional `cik-A` query value.
    pub fn with_cik_a(mut self, cik_a: Cik) -> Self {
        self.cik_a = Some(cik_a);
        self
    }

    /// Borrows the required ticker.
    pub const fn symbol(&self) -> &Ticker {
        &self.symbol
    }

    /// Borrows the optional literal `cik-A` value.
    pub const fn cik_a(&self) -> Option<&Cik> {
        self.cik_a.as_ref()
    }
}

impl From<Ticker> for SecCompanyProfileQuery {
    fn from(symbol: Ticker) -> Self {
        Self::new(symbol)
    }
}

impl From<&Ticker> for SecCompanyProfileQuery {
    fn from(symbol: &Ticker) -> Self {
        Self::new(symbol.clone())
    }
}

impl QueryParameters for SecCompanyProfileQuery {
    fn encode(&self, encoder: &mut QueryEncoder<'_>) {
        encoder.required("symbol", &self.symbol);
        encoder.optional("cik-A", self.cik_a.as_ref());
    }
}

/// Independent optional SIC code and title filters for the classification list.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct IndustryClassificationsQuery {
    industry_title: Option<SearchTerm>,
    sic_code: Option<SearchTerm>,
}

impl IndustryClassificationsQuery {
    /// Creates an unfiltered classification-list query.
    pub const fn new() -> Self {
        Self {
            industry_title: None,
            sic_code: None,
        }
    }

    /// Sets the optional industry-title filter.
    pub fn with_industry_title(mut self, industry_title: SearchTerm) -> Self {
        self.industry_title = Some(industry_title);
        self
    }

    /// Sets the optional SIC-code filter.
    pub fn with_sic_code(mut self, sic_code: SearchTerm) -> Self {
        self.sic_code = Some(sic_code);
        self
    }

    /// Borrows the optional industry-title filter.
    pub const fn industry_title(&self) -> Option<&SearchTerm> {
        self.industry_title.as_ref()
    }

    /// Borrows the optional SIC-code filter.
    pub const fn sic_code(&self) -> Option<&SearchTerm> {
        self.sic_code.as_ref()
    }
}

impl QueryParameters for IndustryClassificationsQuery {
    fn encode(&self, encoder: &mut QueryEncoder<'_>) {
        encoder.optional("industryTitle", self.industry_title.as_ref());
        encoder.optional("sicCode", self.sic_code.as_ref());
    }
}

/// Independent optional ticker, CIK, and SIC filters for raw classification search.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct IndustryClassificationSearchQuery {
    symbol: Option<Ticker>,
    cik: Option<Cik>,
    sic_code: Option<SearchTerm>,
}

impl IndustryClassificationSearchQuery {
    /// Creates an unfiltered industry-classification search.
    pub const fn new() -> Self {
        Self {
            symbol: None,
            cik: None,
            sic_code: None,
        }
    }

    /// Sets the optional ticker filter.
    pub fn with_symbol(mut self, symbol: Ticker) -> Self {
        self.symbol = Some(symbol);
        self
    }

    /// Sets the optional CIK filter.
    pub fn with_cik(mut self, cik: Cik) -> Self {
        self.cik = Some(cik);
        self
    }

    /// Sets the optional SIC-code filter.
    pub fn with_sic_code(mut self, sic_code: SearchTerm) -> Self {
        self.sic_code = Some(sic_code);
        self
    }

    /// Borrows the optional ticker filter.
    pub const fn symbol(&self) -> Option<&Ticker> {
        self.symbol.as_ref()
    }

    /// Borrows the optional CIK filter.
    pub const fn cik(&self) -> Option<&Cik> {
        self.cik.as_ref()
    }

    /// Borrows the optional SIC-code filter.
    pub const fn sic_code(&self) -> Option<&SearchTerm> {
        self.sic_code.as_ref()
    }
}

impl QueryParameters for IndustryClassificationSearchQuery {
    fn encode(&self, encoder: &mut QueryEncoder<'_>) {
        encoder.optional("symbol", self.symbol.as_ref());
        encoder.optional("cik", self.cik.as_ref());
        encoder.optional("sicCode", self.sic_code.as_ref());
    }
}

/// Optional pagination for the all-company industry-classification feed.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct AllIndustryClassificationsQuery {
    page: Option<Page>,
    limit: Option<Limit>,
}

impl AllIndustryClassificationsQuery {
    /// Creates a query without undocumented pagination defaults.
    pub const fn new() -> Self {
        Self {
            page: None,
            limit: None,
        }
    }

    /// Sets the optional provider page index.
    pub const fn with_page(mut self, page: Page) -> Self {
        self.page = Some(page);
        self
    }

    /// Sets the optional provider result limit.
    pub const fn with_limit(mut self, limit: Limit) -> Self {
        self.limit = Some(limit);
        self
    }

    /// Returns the optional provider page index.
    pub const fn page(&self) -> Option<Page> {
        self.page
    }

    /// Returns the optional provider result limit.
    pub const fn limit(&self) -> Option<Limit> {
        self.limit
    }
}

impl QueryParameters for AllIndustryClassificationsQuery {
    fn encode(&self, encoder: &mut QueryEncoder<'_>) {
        encoder.optional("page", self.page);
        encoder.optional("limit", self.limit);
    }
}

const LATEST_FILING_METADATA: EndpointMetadata = EndpointMetadata::new()
    .with_geography(GeographicAvailability::UsOnly)
    .with_bounds(
        EndpointBounds::new()
            .with_response_rows(1_000)
            .with_page(100)
            .with_date_range_days(90),
    );
const FILING_SEARCH_METADATA: EndpointMetadata = EndpointMetadata::new()
    .with_geography(GeographicAvailability::UsOnly)
    .with_bounds(
        EndpointBounds::new()
            .with_response_rows(1_000)
            .with_page(100),
    );
const SEC_COMPANY_METADATA: EndpointMetadata =
    EndpointMetadata::new().with_geography(GeographicAvailability::UsOnly);

/// Describes `GET sec-filings-8k` without binding a transport.
pub fn latest_8k_sec_filings(
    query: Latest8kSecFilingsQuery,
) -> EndpointSpec<Latest8kSecFilingsQuery, Vec<SecFiling>> {
    EndpointSpec::get("sec-filings-8k", "sec-filings-8k", query)
        .with_metadata(LATEST_FILING_METADATA)
}

/// Describes `GET sec-filings-financials` without binding a transport.
pub fn latest_sec_filings(
    query: LatestSecFilingsQuery,
) -> EndpointSpec<LatestSecFilingsQuery, Vec<SecFiling>> {
    EndpointSpec::get("sec-filings-financials", "sec-filings-financials", query)
        .with_metadata(LATEST_FILING_METADATA)
}

/// Describes `GET sec-filings-search/form-type` without binding a transport.
pub fn sec_filings_by_form_type(
    query: SecFilingsByFormTypeQuery,
) -> EndpointSpec<SecFilingsByFormTypeQuery, Vec<SecFiling>> {
    EndpointSpec::get(
        "sec-filings-search/form-type",
        "sec-filings-search/form-type",
        query,
    )
    .with_metadata(FILING_SEARCH_METADATA)
}

/// Describes `GET sec-filings-search/symbol` without binding a transport.
pub fn sec_filings_by_symbol(
    query: SecFilingsBySymbolQuery,
) -> EndpointSpec<SecFilingsBySymbolQuery, Vec<SecFiling>> {
    EndpointSpec::get(
        "sec-filings-search/symbol",
        "sec-filings-search/symbol",
        query,
    )
    .with_metadata(FILING_SEARCH_METADATA)
}

/// Describes `GET sec-filings-search/cik` without binding a transport.
pub fn sec_filings_by_cik(
    query: SecFilingsByCikQuery,
) -> EndpointSpec<SecFilingsByCikQuery, Vec<SecFiling>> {
    EndpointSpec::get("sec-filings-search/cik", "sec-filings-search/cik", query)
        .with_metadata(FILING_SEARCH_METADATA)
}

/// Describes `GET sec-filings-company-search/name` without binding a transport.
pub fn search_sec_companies_by_name(
    query: SecCompaniesByNameQuery,
) -> EndpointSpec<SecCompaniesByNameQuery, Vec<SecCompanySearchResult>> {
    EndpointSpec::get(
        "sec-filings-company-search/name",
        "sec-filings-company-search/name",
        query,
    )
    .with_metadata(SEC_COMPANY_METADATA)
}

/// Describes `GET sec-filings-company-search/symbol` without binding a transport.
pub fn search_sec_companies_by_symbol(
    query: SecCompaniesBySymbolQuery,
) -> EndpointSpec<SecCompaniesBySymbolQuery, Vec<SecCompanySearchResult>> {
    EndpointSpec::get(
        "sec-filings-company-search/symbol",
        "sec-filings-company-search/symbol",
        query,
    )
    .with_metadata(SEC_COMPANY_METADATA)
}

/// Describes `GET sec-filings-company-search/cik` without binding a transport.
pub fn search_sec_companies_by_cik(
    query: SecCompaniesByCikQuery,
) -> EndpointSpec<SecCompaniesByCikQuery, Vec<SecCompanySearchResult>> {
    EndpointSpec::get(
        "sec-filings-company-search/cik",
        "sec-filings-company-search/cik",
        query,
    )
    .with_metadata(SEC_COMPANY_METADATA)
}

/// Describes `GET sec-profile` without binding a transport.
pub fn sec_company_profile(
    query: SecCompanyProfileQuery,
) -> EndpointSpec<SecCompanyProfileQuery, Vec<SecCompanyProfile>> {
    EndpointSpec::get("sec-profile", "sec-profile", query).with_metadata(SEC_COMPANY_METADATA)
}

/// Describes `GET standard-industrial-classification-list` without binding a transport.
pub fn industry_classifications(
    query: IndustryClassificationsQuery,
) -> EndpointSpec<IndustryClassificationsQuery, Vec<SicClassification>> {
    EndpointSpec::get(
        "standard-industrial-classification-list",
        "standard-industrial-classification-list",
        query,
    )
    .with_metadata(SEC_COMPANY_METADATA)
}

/// Describes `GET industry-classification-search` without binding a transport.
pub fn search_industry_classifications(
    query: IndustryClassificationSearchQuery,
) -> EndpointSpec<IndustryClassificationSearchQuery, Vec<DynamicObject>> {
    EndpointSpec::get(
        "industry-classification-search",
        "industry-classification-search",
        query,
    )
    .with_metadata(SEC_COMPANY_METADATA)
}

/// Describes `GET all-industry-classification` without binding a transport.
pub fn all_industry_classifications(
    query: AllIndustryClassificationsQuery,
) -> EndpointSpec<AllIndustryClassificationsQuery, Vec<SecCompanySearchResult>> {
    EndpointSpec::get(
        "all-industry-classification",
        "all-industry-classification",
        query,
    )
    .with_metadata(SEC_COMPANY_METADATA)
}

impl Client {
    /// Retrieves the latest US 8-K SEC filings within the required date range.
    pub async fn latest_8k_sec_filings(
        &self,
        query: impl Into<Latest8kSecFilingsQuery>,
    ) -> Result<Vec<SecFiling>> {
        self.execute(&latest_8k_sec_filings(query.into())).await
    }

    /// Retrieves the latest US financial SEC filings within the required date range.
    pub async fn latest_sec_filings(
        &self,
        query: impl Into<LatestSecFilingsQuery>,
    ) -> Result<Vec<SecFiling>> {
        self.execute(&latest_sec_filings(query.into())).await
    }

    /// Retrieves US SEC filings by their open form type.
    pub async fn sec_filings_by_form_type(
        &self,
        query: impl Into<SecFilingsByFormTypeQuery>,
    ) -> Result<Vec<SecFiling>> {
        self.execute(&sec_filings_by_form_type(query.into())).await
    }

    /// Retrieves US SEC filings for a ticker.
    pub async fn sec_filings_by_symbol(
        &self,
        query: impl Into<SecFilingsBySymbolQuery>,
    ) -> Result<Vec<SecFiling>> {
        self.execute(&sec_filings_by_symbol(query.into())).await
    }

    /// Retrieves US SEC filings for a string-backed CIK.
    pub async fn sec_filings_by_cik(
        &self,
        query: impl Into<SecFilingsByCikQuery>,
    ) -> Result<Vec<SecFiling>> {
        self.execute(&sec_filings_by_cik(query.into())).await
    }

    /// Searches US SEC companies by company-name text.
    pub async fn search_sec_companies_by_name(
        &self,
        query: impl Into<SecCompaniesByNameQuery>,
    ) -> Result<Vec<SecCompanySearchResult>> {
        self.execute(&search_sec_companies_by_name(query.into()))
            .await
    }

    /// Searches US SEC companies by ticker.
    pub async fn search_sec_companies_by_symbol(
        &self,
        query: impl Into<SecCompaniesBySymbolQuery>,
    ) -> Result<Vec<SecCompanySearchResult>> {
        self.execute(&search_sec_companies_by_symbol(query.into()))
            .await
    }

    /// Searches US SEC companies by string-backed CIK.
    pub async fn search_sec_companies_by_cik(
        &self,
        query: impl Into<SecCompaniesByCikQuery>,
    ) -> Result<Vec<SecCompanySearchResult>> {
        self.execute(&search_sec_companies_by_cik(query.into()))
            .await
    }

    /// Retrieves the full US SEC company profile for a ticker.
    pub async fn sec_company_profile(
        &self,
        query: impl Into<SecCompanyProfileQuery>,
    ) -> Result<Vec<SecCompanyProfile>> {
        self.execute(&sec_company_profile(query.into())).await
    }

    /// Retrieves the US Standard Industrial Classification directory.
    pub async fn industry_classifications(
        &self,
        query: impl Into<IndustryClassificationsQuery>,
    ) -> Result<Vec<SicClassification>> {
        self.execute(&industry_classifications(query.into())).await
    }

    /// Searches US industry classifications while preserving raw documented rows.
    pub async fn search_industry_classifications(
        &self,
        query: impl Into<IndustryClassificationSearchQuery>,
    ) -> Result<Vec<DynamicObject>> {
        self.execute(&search_industry_classifications(query.into()))
            .await
    }

    /// Retrieves the paginated US company industry-classification feed.
    pub async fn all_industry_classifications(
        &self,
        query: impl Into<AllIndustryClassificationsQuery>,
    ) -> Result<Vec<SecCompanySearchResult>> {
        self.execute(&all_industry_classifications(query.into()))
            .await
    }
}

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

    fn pairs(query: &impl QueryParameters) -> Vec<(String, String)> {
        let mut pairs = Vec::new();
        query.encode(&mut QueryEncoder::new(&mut |name, value| {
            pairs.push((name.to_owned(), value.to_owned()));
        }));
        pairs
    }

    #[test]
    fn queries_emit_exact_keys_in_documented_order_and_omit_absent_values() {
        let from = Date::parse("2024-01-01").unwrap();
        let to = Date::parse("2024-03-01").unwrap();
        assert_eq!(
            pairs(&Latest8kSecFilingsQuery::new(from, to)),
            [
                ("from".into(), "2024-01-01".into()),
                ("to".into(), "2024-03-01".into())
            ]
        );
        assert_eq!(
            pairs(
                &LatestSecFilingsQuery::new(from, to)
                    .with_page(Page(0))
                    .with_limit(Limit(100))
            ),
            [
                ("from".into(), "2024-01-01".into()),
                ("to".into(), "2024-03-01".into()),
                ("page".into(), "0".into()),
                ("limit".into(), "100".into()),
            ]
        );
        assert_eq!(
            pairs(
                &SecFilingsByFormTypeQuery::new(FormType::new("8-K").unwrap(), from, to)
                    .with_page(Page(0))
                    .with_limit(Limit(u32::MAX))
            ),
            [
                ("formType".into(), "8-K".into()),
                ("from".into(), "2024-01-01".into()),
                ("to".into(), "2024-03-01".into()),
                ("page".into(), "0".into()),
                ("limit".into(), u32::MAX.to_string()),
            ]
        );
        assert_eq!(
            pairs(&SecFilingsBySymbolQuery::new(
                Ticker::new("AAPL").unwrap(),
                from,
                to,
            )),
            [
                ("symbol".into(), "AAPL".into()),
                ("from".into(), "2024-01-01".into()),
                ("to".into(), "2024-03-01".into()),
            ]
        );
        assert_eq!(
            pairs(
                &SecFilingsByCikQuery::new(Cik::new("0000320193").unwrap(), from, to,)
                    .with_page(Page(0))
                    .with_limit(Limit(100))
            ),
            [
                ("cik".into(), "0000320193".into()),
                ("from".into(), "2024-01-01".into()),
                ("to".into(), "2024-03-01".into()),
                ("page".into(), "0".into()),
                ("limit".into(), "100".into()),
            ]
        );
        assert_eq!(
            pairs(&SecCompaniesByNameQuery::new(
                SearchTerm::new("Berkshire").unwrap(),
            )),
            [("company".into(), "Berkshire".into())]
        );
        assert_eq!(
            pairs(&SecCompaniesBySymbolQuery::new(
                Ticker::new("AAPL").unwrap(),
            )),
            [("symbol".into(), "AAPL".into())]
        );
        assert_eq!(
            pairs(&SecCompaniesByCikQuery::new(
                Cik::new("0000320193").unwrap(),
            )),
            [("cik".into(), "0000320193".into())]
        );
        assert_eq!(
            pairs(
                &SecCompanyProfileQuery::new(Ticker::new("AAPL").unwrap())
                    .with_cik_a(Cik::new("0000320193").unwrap())
            ),
            [
                ("symbol".into(), "AAPL".into()),
                ("cik-A".into(), "0000320193".into()),
            ]
        );
        assert!(pairs(&IndustryClassificationsQuery::new()).is_empty());
        assert!(pairs(&IndustryClassificationSearchQuery::new()).is_empty());
        assert!(pairs(&AllIndustryClassificationsQuery::new()).is_empty());
        assert_eq!(
            pairs(
                &AllIndustryClassificationsQuery::new()
                    .with_page(Page(0))
                    .with_limit(Limit(100))
            ),
            [("page".into(), "0".into()), ("limit".into(), "100".into())]
        );
    }

    #[test]
    fn optional_classification_filters_remain_independent() {
        let list = IndustryClassificationsQuery::new()
            .with_industry_title(SearchTerm::new("SERVICES, NEC").unwrap())
            .with_sic_code(SearchTerm::new("07371").unwrap());
        assert_eq!(
            pairs(&list),
            [
                ("industryTitle".into(), "SERVICES, NEC".into()),
                ("sicCode".into(), "07371".into()),
            ]
        );

        let search = IndustryClassificationSearchQuery::new()
            .with_symbol(Ticker::new("000001.SZ").unwrap())
            .with_cik(Cik::new("0000320193").unwrap())
            .with_sic_code(SearchTerm::new("07371").unwrap());
        assert_eq!(
            pairs(&search),
            [
                ("symbol".into(), "000001.SZ".into()),
                ("cik".into(), "0000320193".into()),
                ("sicCode".into(), "07371".into()),
            ]
        );
    }
}