cdg_api/cdg_types.rs
1//! # CDG Types
2//!
3//! This module defines various types used by the CDG API client, particularly enums for API
4//! endpoint parameters.
5
6use serde::{Deserialize, Serialize};
7
8// =========================================
9// Enums for API Endpoint Parameters Values
10// =========================================
11
12/// Enum representing the response formats available for API endpoints.
13///
14/// This enum is used to specify the desired format of the API response,
15/// allowing consumers to choose between JSON and XML formats.
16#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
17#[serde(rename_all = "lowercase")]
18pub enum FormatType {
19 /// JSON format.
20 #[default]
21 Json,
22
23 /// XML format.
24 Xml,
25}
26
27impl FormatType {
28 /// Converts the [`FormatType`] variant to its corresponding query parameter string.
29 ///
30 /// # Returns
31 ///
32 /// A [`String`] representing the query parameter (e.g., `"format=json"`).
33 pub fn to_query_param(&self) -> String {
34 match self {
35 FormatType::Json => "format=json".to_string(),
36 FormatType::Xml => "format=xml".to_string(),
37 }
38 }
39
40 /// Converts the [`FormatType`] variant to its lowercase string representation.
41 ///
42 /// # Returns
43 ///
44 /// A [`String`] representing the format type (e.g., `"json"` or `"xml"`).
45 pub fn to_string(&self) -> String {
46 match self {
47 FormatType::Json => "json".to_string(),
48 FormatType::Xml => "xml".to_string(),
49 }
50 }
51}
52
53/// Enum representing the sorting options available for API endpoints.
54///
55/// This enum allows consumers to sort responses based on update dates
56/// in ascending or descending order.
57#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
58#[serde(rename_all = "lowercase")]
59pub enum SortType {
60 /// SortType by update date in ascending order.
61 #[default]
62 UpdateDateAsc,
63
64 /// SortType by update date in descending order.
65 UpdateDateDesc,
66}
67
68impl SortType {
69 /// Converts the [`SortType`] variant to its corresponding query parameter string.
70 ///
71 /// # Returns
72 ///
73 /// A [`String`] representing the sort query parameter
74 /// (e.g., `"sort=updateDate+asc"`).
75 pub fn to_query_param(&self) -> String {
76 match self {
77 SortType::UpdateDateAsc => "sort=updateDate+asc".to_string(),
78 SortType::UpdateDateDesc => "sort=updateDate+desc".to_string(),
79 }
80 }
81
82 /// Converts the [`SortType`] variant to its lowercase string representation.
83 ///
84 /// # Returns
85 ///
86 /// A [`String`] representing the sort order (`"asc"` or `"desc"`).
87 pub fn to_string(&self) -> String {
88 match self {
89 SortType::UpdateDateAsc => "asc".to_string(),
90 SortType::UpdateDateDesc => "desc".to_string(),
91 }
92 }
93}
94
95/// Enum representing various bill types in legislative processes.
96///
97/// This enum categorizes bills based on their origin and nature within
98/// the legislative system.
99#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
100pub enum BillType {
101 /// House Resolution ([`hr`]).
102 #[default]
103 Hr, // House Resolution
104
105 /// Senate Bill ([`s`]).
106 S, // Senate
107
108 /// House Joint Resolution ([`hjres`]).
109 Hjres, // House Joint Resolution
110
111 /// Senate Joint Resolution ([`sjres`]).
112 Sjres, // Senate Joint Resolution
113
114 /// House Concurrent Resolution ([`hconres`]).
115 Hconres, // House Concurrent Resolution
116
117 /// Senate Concurrent Resolution ([`sconres`]).
118 Sconres, // Senate Concurrent Resolution
119
120 /// House Simple Resolution ([`hres`]).
121 Hres, // House Simple Resolution
122
123 /// Senate Simple Resolution ([`sres`]).
124 Sres, // Senate Simple Resolution
125}
126
127impl BillType {
128 /// Converts the [`BillType`] variant to its lowercase string representation.
129 ///
130 /// # Returns
131 ///
132 /// A [`String`] representing the bill type (e.g., `"hr"`, `"s"`, etc.).
133 pub fn to_string(&self) -> String {
134 match self {
135 BillType::Hr => "hr".to_string(),
136 BillType::S => "s".to_string(),
137 BillType::Hjres => "hjres".to_string(),
138 BillType::Sjres => "sjres".to_string(),
139 BillType::Hconres => "hconres".to_string(),
140 BillType::Sconres => "sconres".to_string(),
141 BillType::Hres => "hres".to_string(),
142 BillType::Sres => "sres".to_string(),
143 }
144 }
145
146 /// Converts a `&str` to the corresponding [`BillType`] variant.
147 pub fn from_str(s: &str) -> Option<BillType> {
148 match s.to_lowercase().as_str() {
149 "hr" => Some(BillType::Hr),
150 "s" => Some(BillType::S),
151 "hjres" => Some(BillType::Hjres),
152 "sjres" => Some(BillType::Sjres),
153 "hconres" => Some(BillType::Hconres),
154 "sconres" => Some(BillType::Sconres),
155 "hres" => Some(BillType::Hres),
156 "sres" => Some(BillType::Sres),
157 _ => None,
158 }
159 }
160}
161
162/// Enum representing the types of amendments in legislative processes.
163///
164/// This enum categorizes amendments based on their origin within
165/// the legislative chambers.
166#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
167pub enum AmendmentType {
168 /// House Amendment ([`hamdt`]).
169 Hamdt, // House Amendment
170
171 /// Senate Amendment ([`samdt`]).
172 #[default]
173 Samdt, // Senate Amendment
174
175 /// Senate Unnumbered Amendment ([`suamdt`]).
176 Suamdt, // Senate Unnumbered Amendment
177}
178
179impl AmendmentType {
180 /// Converts the [`AmendmentType`] variant to its lowercase string representation.
181 ///
182 /// # Returns
183 ///
184 /// A [`String`] representing the amendment type (e.g., `"hamdt"`, `"samdt"`, etc.).
185 pub fn to_string(&self) -> String {
186 match self {
187 AmendmentType::Hamdt => "hamdt".to_string(),
188 AmendmentType::Samdt => "samdt".to_string(),
189 AmendmentType::Suamdt => "suamdt".to_string(),
190 }
191 }
192}
193
194/// Enum representing the chambers of Congress.
195///
196/// This enum distinguishes between the House, Senate, and Joint committees
197/// within the legislative body.
198#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
199pub enum ChamberType {
200 /// House chamber.
201 House,
202
203 /// Senate chamber.
204 #[default]
205 Senate,
206
207 /// Joint chamber (both House and Senate).
208 Joint,
209
210 /// No chamber specified.
211 NoChamber,
212}
213
214impl ChamberType {
215 /// Converts the [`ChamberType`] variant to its lowercase string representation.
216 ///
217 /// # Returns
218 ///
219 /// A [`String`] representing the chamber type (e.g., `"house"`, `"senate"`, `"joint"`).
220 pub fn to_string(&self) -> String {
221 match self {
222 ChamberType::House => "house".to_string(),
223 ChamberType::Senate => "senate".to_string(),
224 ChamberType::Joint => "joint".to_string(),
225 ChamberType::NoChamber => "nochamber".to_string(),
226 }
227 }
228}
229
230/// Enum representing different types of communications handled by committees.
231///
232/// This enum categorizes the various communication types such as executive
233/// communications, presidential messages, petitions, etc.
234#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
235pub enum CommunicationType {
236 /// Executive Communication ([`ec`]).
237 #[default]
238 Ec, // Executive Communication
239
240 /// Message from the President ([`ml`]).
241 Ml, // Message from the President
242
243 /// Presidential Message ([`pm`]).
244 Pm, // Presidential Message
245
246 /// Petition ([`pt`]).
247 Pt, // Petition
248}
249
250impl CommunicationType {
251 /// Converts the [`CommunicationType`] variant to its lowercase string representation.
252 ///
253 /// # Returns
254 ///
255 /// A [`String`] representing the communication type (e.g., `"ec"`, `"ml"`, etc.).
256 pub fn to_string(&self) -> String {
257 match self {
258 CommunicationType::Ec => "ec".to_string(),
259 CommunicationType::Ml => "ml".to_string(),
260 CommunicationType::Pm => "pm".to_string(),
261 CommunicationType::Pt => "pt".to_string(),
262 }
263 }
264}
265
266/// Enum representing different types of laws.
267///
268/// This enum distinguishes between public and private laws.
269#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
270pub enum LawType {
271 /// Public Law ([`pub`]).
272 #[default]
273 Pub, // Public Law
274
275 /// Private Law ([`priv`]).
276 Priv, // Private Law
277}
278
279impl LawType {
280 /// Converts the [`LawType`] variant to its lowercase string representation.
281 ///
282 /// # Returns
283 ///
284 /// A [`String`] representing the law type (`"pub"` or `"priv"`).
285 pub fn to_string(&self) -> String {
286 match self {
287 LawType::Pub => "pub".to_string(),
288 LawType::Priv => "priv".to_string(),
289 }
290 }
291}
292
293/// Enum representing the types of committee reports.
294///
295/// This enum categorizes committee reports based on their origin within
296/// the legislative chambers.
297#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
298pub enum CommitteeReportType {
299 /// House Report ([`hrpt`]).
300 Hrpt, // House Report
301
302 /// Senate Report ([`srpt`]).
303 Srpt, // Senate Report
304
305 /// House Document ([`hdoc`]).
306 Hdoc, // House Document
307
308 /// Senate Document ([`sdoc`]).
309 Sdoc, // Senate Document
310
311 /// Conference Report ([`crpt`]).
312 #[default]
313 Crpt, // Conference Report
314}
315
316impl CommitteeReportType {
317 /// Converts the [`CommitteeReportType`] variant to its lowercase string representation.
318 ///
319 /// # Returns
320 ///
321 /// A [`String`] representing the committee report type (e.g., `"hrpt"`, `"srpt"`, etc.).
322 pub fn to_string(&self) -> String {
323 match self {
324 CommitteeReportType::Hrpt => "hrpt".to_string(),
325 CommitteeReportType::Srpt => "srpt".to_string(),
326 CommitteeReportType::Hdoc => "hdoc".to_string(),
327 CommitteeReportType::Sdoc => "sdoc".to_string(),
328 CommitteeReportType::Crpt => "crpt".to_string(),
329 }
330 }
331}