Skip to main content

gingr/endpoint/
report_cards_files.rs

1use super::{LocationId, Method, Request};
2
3fn push_optional<T: core::fmt::Display>(
4    params: &mut Vec<(String, String)>,
5    key: &str,
6    value: Option<T>,
7) {
8    if let Some(value) = value {
9        params.push((key.to_owned(), value.to_string()));
10    }
11}
12
13#[derive(Clone, Debug, Default, PartialEq, Eq)]
14/// Request descriptor for Gingr report-card file metadata used as source material for Pawgress-style customer updates.
15pub struct ReportCardFiles {
16    number_days: Option<u64>,
17    limit: Option<u64>,
18    location_id: Option<LocationId>,
19}
20
21impl ReportCardFiles {
22    /// Starts a builder that makes each provider parameter explicit before request capture.
23    pub fn builder() -> ReportCardFilesBuilder {
24        ReportCardFilesBuilder::default()
25    }
26}
27
28#[derive(Clone, Debug, Default)]
29/// Builder for report-card file lookup filters by owner, animal, reservation, and location.
30pub struct ReportCardFilesBuilder {
31    number_days: Option<u64>,
32    limit: Option<u64>,
33    location_id: Option<LocationId>,
34}
35
36impl ReportCardFilesBuilder {
37    /// Limits report-card file lookup to a recent day window.
38    pub fn number_days(mut self, number_days: u64) -> Self {
39        self.number_days = Some(number_days);
40        self
41    }
42
43    /// Sets the provider result limit so automation does not imply unbounded source coverage.
44    pub fn limit(mut self, limit: u64) -> Self {
45        self.limit = Some(limit);
46        self
47    }
48
49    /// Scopes the Gingr endpoint request to a location.
50    pub fn location_id(mut self, location_id: LocationId) -> Self {
51        self.location_id = Some(location_id);
52        self
53    }
54
55    /// Finalizes the provider request descriptor after required fields are present and wrappers have validated local invariants.
56    pub fn build(self) -> ReportCardFiles {
57        ReportCardFiles {
58            number_days: self.number_days,
59            limit: self.limit,
60            location_id: self.location_id,
61        }
62    }
63}
64
65impl Request for ReportCardFiles {
66    fn method(&self) -> Method {
67        Method::Get
68    }
69
70    fn path(&self) -> &'static str {
71        "/api/v1/report_card_files"
72    }
73
74    fn parameters(&self) -> Vec<(String, String)> {
75        let mut params = Vec::new();
76        push_optional(&mut params, "number_days", self.number_days);
77        push_optional(&mut params, "limit", self.limit);
78        push_optional(&mut params, "location_id", self.location_id);
79        params
80    }
81}