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
use anyhow::Result;

use crate::Client;

pub struct BookingData {
    pub client: Client,
}

impl BookingData {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        BookingData { client }
    }

    /**
     * Your company's bookings.
     *
     * This function performs a `GET` to the `/v1/bookings` endpoint.
     *
     * Return booking rows filtered by the parameters you select.
     *
     * **Parameters:**
     *
     * * `created_from: &str` -- Filter based on booking created date in epoch seconds.
     * * `created_to: &str` -- Filter based on booking created date in epoch seconds.
     * * `start_date_from: &str` -- Filter based on travel start date in epoch seconds.
     * * `start_date_to: &str` -- Filter based on travel end date in epoch seconds.
     * * `booking_status: crate::types::BookingStatus` -- Filter based on booking status.
     * * `page: u64` -- Page cursor for use in pagination.
     * * `size: i64` -- Number of records returned per page.
     * * `booking_type: crate::types::BookingType` -- Filter based on Booking type.
     */
    pub async fn get_booking_report(
        &self,
        created_from: &str,
        created_to: &str,
        start_date_from: &str,
        start_date_to: &str,
        booking_status: crate::types::BookingStatus,
        page: u64,
        size: i64,
        booking_type: crate::types::BookingType,
    ) -> Result<Vec<crate::types::BookingReport>> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !booking_status.to_string().is_empty() {
            query_args.push(("bookingStatus".to_string(), booking_status.to_string()));
        }
        if !booking_type.to_string().is_empty() {
            query_args.push(("bookingType".to_string(), booking_type.to_string()));
        }
        if !created_from.is_empty() {
            query_args.push(("createdFrom".to_string(), created_from.to_string()));
        }
        if !created_to.is_empty() {
            query_args.push(("createdTo".to_string(), created_to.to_string()));
        }
        if !page.to_string().is_empty() {
            query_args.push(("page".to_string(), page.to_string()));
        }
        if size > 0 {
            query_args.push(("size".to_string(), size.to_string()));
        }
        if !start_date_from.is_empty() {
            query_args.push(("startDateFrom".to_string(), start_date_from.to_string()));
        }
        if !start_date_to.is_empty() {
            query_args.push(("startDateTo".to_string(), start_date_to.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/v1/bookings?{}", query_);

        let resp: crate::types::BookingReportResponse = self.client.get(&url, None).await?;

        // Return our response data.
        Ok(resp.data.to_vec())
    }

    /**
     * Your company's bookings.
     *
     * This function performs a `GET` to the `/v1/bookings` endpoint.
     *
     * As opposed to `get_booking_report`, this function returns all the pages of the request at once.
     *
     * Return booking rows filtered by the parameters you select.
     */
    pub async fn get_all_booking_report(
        &self,
        created_from: &str,
        created_to: &str,
        start_date_from: &str,
        start_date_to: &str,
        booking_status: crate::types::BookingStatus,
        booking_type: crate::types::BookingType,
    ) -> Result<Vec<crate::types::BookingReport>> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !booking_status.to_string().is_empty() {
            query_args.push(("bookingStatus".to_string(), booking_status.to_string()));
        }
        if !booking_type.to_string().is_empty() {
            query_args.push(("bookingType".to_string(), booking_type.to_string()));
        }
        if !created_from.is_empty() {
            query_args.push(("createdFrom".to_string(), created_from.to_string()));
        }
        if !created_to.is_empty() {
            query_args.push(("createdTo".to_string(), created_to.to_string()));
        }
        if !start_date_from.is_empty() {
            query_args.push(("startDateFrom".to_string(), start_date_from.to_string()));
        }
        if !start_date_to.is_empty() {
            query_args.push(("startDateTo".to_string(), start_date_to.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/v1/bookings?{}", query_);

        let mut resp: crate::types::BookingReportResponse = if !url.contains('?') {
            self.client
                .get(&format!("{}?page=0&size=100", url), None)
                .await?
        } else {
            self.client
                .get(&format!("{}&page=0&size=100", url), None)
                .await?
        };

        let mut data = resp.data;
        let mut page = resp.page.current_page + 1;

        // Paginate if we should.
        while page <= (resp.page.total_pages - 1) {
            if !url.contains('?') {
                resp = self
                    .client
                    .get(&format!("{}?page={}&size=100", url, page), None)
                    .await?;
            } else {
                resp = self
                    .client
                    .get(&format!("{}&page={}&size=100", url, page), None)
                    .await?;
            }

            data.append(&mut resp.data);

            page = resp.page.current_page + 1;
        }

        // Return our response data.
        Ok(data)
    }
}