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
#![deny(warnings)]
#![deny(unused)]
#![deny(clippy::expect_used)]
#![deny(clippy::get_unwrap)]
#![deny(clippy::exit)]
#![deny(clippy::indexing_slicing)]
#![deny(clippy::panic)]
#![deny(clippy::panic_in_result_fn)]
#![deny(clippy::unreachable)]
#![deny(clippy::print_stdout)]
#![allow(clippy::upper_case_acronyms)]

//! # Fortnite API
//! This crate is a wrapper for the Fortnite API.
//!
//! ## Usage
//!
//! ```rust no_run
//! #[tokio::main]
//! async fn main() {
//!     let http_client = reqwest::Client::new();
//!
//!     let result = fortnite_api::get_news_v2(&http_client, None).await;
//!     println!("Result: {:#?}", result);
//!     assert!(result.is_ok());
//! }
//! ```
//!
//! ## Endpoints
//!
//! | Endpoint | Function | Result Type |
//! | --- | --- | --- |
//! | AES V2 | [`get_aes_keys_v2`] | [`AesV2`] |
//! | Banners V1 | [`get_banners_v1`] | [`BannersV1`] |
//! | Banners Colors V1 | [`get_banners_colors_v1`] | [`BannersColorsV1`] |
//! | Cosmetics V2 | [`get_cosmetics_v2`] | [`CosmeticsV2`] |
//! | Cosmetics New V2 | [`get_cosmetics_new_v2`] | [`CosmeticsNewV2`] |
//! | Cosmetic By ID V2 | [`get_cosmetic_by_id_v2`] | [`CosmeticV2`] |
//! | Creator Code V2 | [`get_creatorcode_v2`] | [`CreatorCodeV2`] |
//! | Map V1 | [`get_map_v1`] | [`MapV1`] |
//! | News V2 | [`get_news_v2`] | [`NewsV2`] |
//! | News Gamemode V2 | [`get_news_br_v2`] [`get_news_stw_v2`] [`get_news_creative_v2`] | [`News`] |
//! | Playlists V1 | [`get_playlists_v1`] | [`PlaylistsV1`] |
//! | Playlists By ID V1 | [`get_playlist_by_id_v1`] | [`PlaylistV1`] |
//! | Shop BR V2 | [`get_shop_br_v2`] [`get_shop_combined_v2`] | [`ShopV2`] |
//! | Stats V2 | [`get_stats_v2`] [`get_stats_by_account_id_v2`] | [`StatsV2`] |
//!

use crate::response_types::aes::{AesKeyFormat, AesV2};
use crate::response_types::banners::{BannersColorsV1, BannersV1};
use crate::response_types::cosmetics::{CosmeticV2, CosmeticsNewV2, CosmeticsV2};
use crate::response_types::creatorcode::CreatorCodeV2;
use crate::response_types::map::MapV1;
use crate::response_types::news::{News, NewsV2};
use crate::response_types::playlists::{PlaylistV1, PlaylistsV1};
use crate::response_types::shop::ShopV2;
use crate::response_types::stats::{StatsAccountType, StatsImage, StatsTimeWindow, StatsV2};
use crate::utils::fetch::fetch_endpoint;
use reqwest::Url;
use std::collections::HashMap;
use std::str::FromStr;

pub mod response_types;
pub mod utils;

pub async fn get_aes_keys_v2(
    http_client: &reqwest::Client,
    key_format: Option<AesKeyFormat>,
) -> reqwest::Result<AesV2> {
    //! Get the current AES keys.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `key_format`: The format of the AES keys. Can be `None`, `Some(AesKeyFormat::Hex)`, or `Some(AesKeyFormat::Base64)`.
    //!
    //! ## Returns
    //!
    //! The current AES keys.
    //!
    //! ## Example
    //!
    //! ```rust
    //! use fortnite_api::response_types::aes::AesKeyFormat;
    //!
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_aes_keys_v2(&http_client, Some(AesKeyFormat::Hex)).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/aes").unwrap();
    if let Some(key_format) = key_format {
        url.query_pairs_mut()
            .append_pair("keyFormat", &key_format.to_string());
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_banners_v1(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<BannersV1> {
    //! Get the banners.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the banners. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The banners.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_banners_v1(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v1/banners").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_banners_colors_v1(
    http_client: &reqwest::Client,
) -> reqwest::Result<BannersColorsV1> {
    //! Get the banner colors.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //!
    //! ## Returns
    //!
    //! The banner colors.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_banners_colors_v1(&http_client).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let url = Url::from_str("https://fortnite-api.com/v1/banners/colors").unwrap();

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_cosmetics_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<CosmeticsV2> {
    //! Get the cosmetics.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the cosmetics. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The cosmetics.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_cosmetics_v2(&http_client, None).await;
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/cosmetics/br").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_cosmetics_new_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<CosmeticsNewV2> {
    //! Get the new cosmetics.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the cosmetics. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The new cosmetics.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_cosmetics_new_v2(&http_client, None).await;
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/cosmetics/br/new").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_cosmetic_by_id_v2(
    http_client: &reqwest::Client,
    cosmetic_id: &str,
    language: Option<&str>,
) -> reqwest::Result<CosmeticV2> {
    //! Get the cosmetic by ID.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `cosmetic_id`: The ID of the cosmetic.
    //! - `language`: The language of the cosmetic. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The cosmetic by ID.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_cosmetics_new_v2(&http_client, None).await;
    //!     assert!(result.is_ok());
    //!
    //!     let cosmetic_id = result.unwrap().items.first().unwrap().id.clone();
    //!     let result = fortnite_api::get_cosmetic_by_id_v2(&http_client, &cosmetic_id, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url =
        Url::from_str(format!("https://fortnite-api.com/v2/cosmetics/br/{}", cosmetic_id).as_str())
            .unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_creatorcode_v2(
    http_client: &reqwest::Client,
    name: &str,
) -> reqwest::Result<CreatorCodeV2> {
    //! Get the creator code.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `name`: The name of the creator code.
    //!
    //! ## Returns
    //!
    //! The creator code.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_creatorcode_v2(&http_client, "trymacs").await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/creatorcode").unwrap();
    url.query_pairs_mut().append_pair("name", name);

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_map_v1(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<MapV1> {
    //! Get the map.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the map. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The map.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_map_v1(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v1/map").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_news_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<NewsV2> {
    //! Get the news.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the news. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The news.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_news_v2(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/news").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_news_br_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<News> {
    //! Get the battle royale news.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the news. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The battle royale news.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_news_br_v2(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/news/br").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_news_stw_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<News> {
    //! Get the save the world news.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the news. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The save the world news.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_news_stw_v2(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/news/stw").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_news_creative_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<News> {
    //! Get the creative news.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the news. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The creative news.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_news_creative_v2(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/news/creative").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_playlists_v1(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<PlaylistsV1> {
    //! Get the playlists.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the playlists. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The playlists.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_playlists_v1(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v1/playlists").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_playlist_by_id_v1(
    http_client: &reqwest::Client,
    playlist_id: &str,
    language: Option<&str>,
) -> reqwest::Result<PlaylistV1> {
    //! Get the playlist by ID.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the playlists. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The playlist by ID.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_playlists_v1(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //!
    //!     let playlist_id = result.unwrap().first().unwrap().id.clone();
    //!     let result = fortnite_api::get_playlist_by_id_v1(&http_client, &playlist_id, None).await;
    //!     println!("Result: {:#?}", result);
    //! }
    //! ```
    let mut url =
        Url::from_str(format!("https://fortnite-api.com/v1/playlists/{}", playlist_id).as_str())
            .unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_shop_br_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<ShopV2> {
    //! Get the battle royale shop.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the shop. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The battle royale shop.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_shop_br_v2(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/shop/br").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_shop_combined_v2(
    http_client: &reqwest::Client,
    language: Option<&str>,
) -> reqwest::Result<ShopV2> {
    //! Get the combined shop.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `language`: The language of the shop. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The combined shop.
    //!
    //! ## Example
    //!
    //! ```rust
    //! #[tokio::main]
    //! async fn main() {
    //!     let http_client = reqwest::Client::new();
    //!
    //!     let result = fortnite_api::get_shop_combined_v2(&http_client, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/shop/br/combined").unwrap();
    if let Some(language) = language {
        url.query_pairs_mut().append_pair("language", language);
    }

    fetch_endpoint(http_client, url, "GET", "", &HashMap::new()).await
}

pub async fn get_stats_v2(
    http_client: &reqwest::Client,
    api_key: String,
    name: &str,
    account_type: Option<StatsAccountType>,
    time_window: Option<StatsTimeWindow>,
    image: Option<StatsImage>,
) -> reqwest::Result<StatsV2> {
    //! Get the player stats.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `api_key`: Your Fortnite API key.
    //! - `name`: The name of the player.
    //! - `account_type`: The account type of the player. Can be `None` or [`StatsAccountType`].
    //! - `time_window`: The time window of the stats. Can be `None` or [`StatsTimeWindow`].
    //! - `image`: The image of the stats. Can be `None` or [`StatsImage`].
    //! - `language`: The language of the shop. Can be `None` or a language code.
    //!
    //! ## Returns
    //!
    //! The player stats.
    //!
    //! ## Example
    //!
    //! ```rust,ignore
    //! use fortnite_api::response_types::stats::{StatsAccountType, StatsImage, StatsTimeWindow};
    //!
    //! #[tokio::main]
    //! async fn main() {
    //!     dotenv::dotenv().ok();
    //!     let http_client = reqwest::Client::new();
    //!     let api_key = std::env::var("FORTNITE_API_KEY")
    //!         .expect("Please set the FORTNITE_API_KEY environment variable");
    //!
    //!     let result =
    //!         fortnite_api::get_stats_v2(&http_client, api_key.clone(), "Test", None, None, None).await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url = Url::from_str("https://fortnite-api.com/v2/stats/br/v2").unwrap();
    url.query_pairs_mut().append_pair("name", name);
    if let Some(account_type) = account_type {
        url.query_pairs_mut()
            .append_pair("accountType", &account_type.to_string().to_lowercase());
    }
    if let Some(time_window) = time_window {
        url.query_pairs_mut()
            .append_pair("timeWindow", &time_window.to_string().to_lowercase());
    }
    if let Some(image) = image {
        url.query_pairs_mut()
            .append_pair("image", &image.to_string().to_lowercase());
    }
    let headers = [("Authorization".to_string(), api_key)]
        .into_iter()
        .collect();

    fetch_endpoint(http_client, url, "GET", "", &headers).await
}

pub async fn get_stats_by_account_id_v2(
    http_client: &reqwest::Client,
    api_key: String,
    account_id: &str,
    time_window: Option<StatsTimeWindow>,
    image: Option<StatsImage>,
) -> reqwest::Result<StatsV2> {
    //! Get the player stats by account ID.
    //!
    //! ## Parameters
    //!
    //! - `http_client`: The reqwest client.
    //! - `api_key`: Your Fortnite API key.
    //! - `account_id`: The account ID of the player.
    //! - `time_window`: The time window of the stats. Can be `None` or [`StatsTimeWindow`].
    //! - `image`: The image of the stats. Can be `None` or [`StatsImage`].
    //!
    //! ## Returns
    //!
    //! The player stats.
    //!
    //! ## Example
    //!
    //! ```rust,ignore
    //! use fortnite_api::response_types::stats::{StatsAccountType, StatsImage, StatsTimeWindow};
    //!
    //! #[tokio::main]
    //! async fn main() {
    //!     dotenv::dotenv().ok();
    //!     let http_client = reqwest::Client::new();
    //!     let api_key = std::env::var("FORTNITE_API_KEY")
    //!         .expect("Please set the FORTNITE_API_KEY environment variable");
    //!
    //!     let result = fortnite_api::get_stats_by_account_id_v2(
    //!         &http_client,
    //!         api_key.clone(),
    //!         "3f20d6f579db4e7ba71d80fc18576db2",
    //!         None,
    //!         None,
    //!     )
    //!     .await;
    //!     println!("Result: {:#?}", result);
    //!     assert!(result.is_ok());
    //! }
    //! ```
    let mut url =
        Url::from_str(format!("https://fortnite-api.com/v2/stats/br/v2/{}", account_id).as_str())
            .unwrap();
    if let Some(time_window) = time_window {
        url.query_pairs_mut()
            .append_pair("timeWindow", &time_window.to_string().to_lowercase());
    }
    if let Some(image) = image {
        url.query_pairs_mut()
            .append_pair("image", &image.to_string().to_lowercase());
    }
    let headers = [("Authorization".to_string(), api_key)]
        .into_iter()
        .collect();

    fetch_endpoint(http_client, url, "GET", "", &headers).await
}