submarine 0.1.1

A library for connecting with a subsonic server
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
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
use serde::{Deserialize, Serialize};

/// returned by the server
#[derive(Debug, Deserialize)]
pub(crate) struct OuterResponse {
    #[serde(rename = "subsonic-response")]
    pub(crate) inner: Response,
}

/// contains every possible response from a subsonic server
#[derive(Debug, Deserialize)]
pub(crate) struct Response {
    /// will be send with every response
    #[serde(flatten)]
    pub info: Info,

    /// the type is dependent on the request
    #[serde(flatten)]
    pub data: ResponseType,
}

/// Status of Response from server
#[derive(Debug, Default, PartialEq, Eq)]
pub enum Status {
    Ok,
    #[default]
    Error,
}

/// This is send by every request from server. If a request is 'Status::Ok' the returned
/// Info will be omitted. Requests that doesn't send something
/// back this will be returned instead.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Info {
    #[serde(default, with = "status")]
    pub status: Status,

    /// protocol version
    pub version: String,

    /// identifier of server; returned by navidrome and maybe other servers
    pub r#type: Option<String>,

    /// version of server
    pub server_version: Option<String>,
}

/// every data that is dependent on the request
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum ResponseType {
    Error {
        error: Error,
    },
    Playlists {
        playlists: Playlists,
    },
    #[serde(rename_all = "camelCase")]
    PlaylistWithSongs {
        playlist: PlaylistWithSongs,
    },
    #[serde(rename_all = "camelCase")]
    ScanStatus {
        scan_status: ScanStatus,
    },
    Song {
        song: Box<Child>,
    },
    Artists {
        artists: ArtistsId3,
    },
    Artist {
        artist: ArtistWithAlbumsId3,
    },
    Album {
        album: AlbumWithSongsId3,
    },
    #[serde(rename_all = "camelCase")]
    AlbumList {
        album_list: AlbumList,
    },
    #[serde(rename_all = "camelCase")]
    AlbumList2 {
        album_list2: AlbumList,
    },
    #[serde(rename_all = "camelCase")]
    MusicFolders {
        music_folders: MusicFolders,
    },
    License {
        license: License,
    },
    Indexes {
        indexes: Indexes,
    },
    #[serde(rename_all = "camelCase")]
    MusicDirectory {
        directory: Directory,
    },
    Genres {
        genres: Genres,
    },
    Videos {
        videos: Videos,
    },
    #[serde(rename_all = "camelCase")]
    VideoInfo {
        video_info: VideoInfo,
    },
    #[serde(rename_all = "camelCase")]
    ArtistInfo {
        artist_info: ArtistInfo,
    },
    #[serde(rename_all = "camelCase")]
    ArtistInfo2 {
        artist_info2: ArtistInfo,
    },
    #[serde(rename_all = "camelCase")]
    AlbumInfo {
        album_info: AlbumInfo,
    },
    #[serde(rename_all = "camelCase")]
    SimilarSongs {
        similar_songs: SimilarSongs,
    },
    #[serde(rename_all = "camelCase")]
    SimilarSongs2 {
        similar_songs2: SimilarSongs,
    },
    #[serde(rename_all = "camelCase")]
    TopSongs {
        top_songs: TopSongs,
    },
    #[serde(rename_all = "camelCase")]
    RandomSongs {
        random_songs: Songs,
    },
    #[serde(rename_all = "camelCase")]
    SongsByGenre {
        songs_by_genre: Songs,
    },
    #[serde(rename_all = "camelCase")]
    NowPlaying {
        now_playing: NowPlaying,
    },
    Starred {
        starred: Starred,
    },
    #[serde(rename_all = "camelCase")]
    SearchResult2 {
        search_result2: SearchResult2,
    },
    #[serde(rename_all = "camelCase")]
    SearchResult3 {
        search_result3: SearchResult3,
    },
    Lyrics {
        lyrics: Lyrics,
    },
    Shares {
        shares: Shares,
    },
    Podcasts {
        podcasts: Podcasts,
    },
    #[serde(rename_all = "camelCase")]
    NewestPodcasts {
        newest_podcasts: NewestPodcasts,
    },
    #[serde(rename_all = "camelCase")]
    JukeboxStatus {
        jukebox_status: JukeboxStatus,
    },
    #[serde(rename_all = "camelCase")]
    JukeboxPlaylist {
        jukebox_playlist: JukeboxPlaylist,
    },
    #[serde(rename_all = "camelCase")]
    InternetRadionStations {
        internet_radio_stations: InternetRadioStations,
    },
    #[serde(rename_all = "camelCase")]
    ChatMessages {
        chat_messages: ChatMessages,
    },
    User {
        user: User,
    },
    Users {
        users: Users,
    },
    Bookmarks {
        bookmarks: Bookmarks,
    },
    #[serde(rename_all = "camelCase")]
    PlayQueue {
        play_queue: PlayQueue,
    },
    // order is important or it will allways be matched to ping
    Ping {},
}

#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Serialize)]
pub struct ScanStatus {
    pub scanning: bool,
    pub count: Option<i64>,
    pub folder_count: Option<usize>, //navidrome specific
    pub last_scan: Option<chrono::DateTime<chrono::offset::FixedOffset>>, // navidrome specific
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct ArtistsId3 {
    pub index: Vec<IndexId3>,
}

/// Indexes artists
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct IndexId3 {
    pub name: String,
    pub artist: Vec<ArtistId3>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ArtistId3 {
    pub id: String,
    pub name: String,
    pub cover_art: Option<String>,
    pub artist_image_url: Option<String>,
    pub album_count: i32,
    pub starred: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
}

impl PartialEq for ArtistId3 {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for ArtistId3 {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ArtistWithAlbumsId3 {
    #[serde(flatten)]
    pub base: ArtistId3,
    #[serde(default)]
    pub album: Vec<AlbumId3>,
}

#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub enum UserRating {
    One,
    Two,
    Three,
    Four,
    Five,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct AlbumList {
    pub album: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct AlbumWithSongsId3 {
    #[serde(flatten)]
    pub base: AlbumId3,
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Child {
    pub id: String,
    pub parent: Option<String>,
    #[serde(default)]
    pub is_dir: Option<bool>,
    #[serde(default)] // navidrome specific
    pub title: String,
    #[serde(default)]
    pub name: String,
    pub album: Option<String>,
    pub artist: Option<String>,
    pub track: Option<i32>,
    pub year: Option<i32>,
    pub genre: Option<String>,
    pub cover_art: Option<String>,
    pub size: Option<i64>,
    pub content_type: Option<String>,
    pub suffix: Option<String>,
    pub transcoded_content_type: Option<String>,
    pub transcoded_suffix: Option<String>,
    pub duration: Option<i32>,
    pub bit_rate: Option<i32>,
    pub path: Option<String>,
    pub is_video: Option<bool>,
    pub user_rating: Option<i32>,
    pub average_rating: Option<f64>,
    pub play_count: Option<i64>,
    pub disc_number: Option<i32>,
    pub created: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    pub starred: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    pub album_id: Option<String>,
    pub artist_id: Option<String>,
    pub typ: Option<MediaType>,
    pub bookmark_position: Option<i64>,
    pub original_width: Option<i32>,
    pub original_height: Option<i32>,
}

impl PartialEq for Child {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for Child {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub enum MediaType {
    Music,
    Podcast,
    Audiobook,
    Video,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct Playlists {
    #[serde(default)]
    pub playlist: Vec<Playlist>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Playlist {
    pub allowed_user: Option<Vec<String>>,
    pub id: String,
    pub name: String,
    pub comment: Option<String>,
    pub owner: Option<String>,
    pub public: Option<bool>,
    pub song_count: i32,
    pub duration: i32,
    pub created: chrono::DateTime<chrono::offset::FixedOffset>,
    pub changed: chrono::DateTime<chrono::offset::FixedOffset>,
    pub cover_art: Option<String>,
}

impl PartialEq for Playlist {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for Playlist {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PlaylistWithSongs {
    #[serde(flatten)]
    pub base: Playlist,
    #[serde(default)]
    pub entry: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct Error {
    pub code: i32,
    pub message: String,
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}: {}", self.code, self.message)
    }
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct License {
    pub valid: bool,
    pub email: Option<String>,
    pub license_expires: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    pub trial_expires: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct MusicFolders {
    pub music_folder: Vec<MusicFolder>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MusicFolder {
    pub id: i32,
    pub name: Option<String>,
}

impl PartialEq for MusicFolder {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for MusicFolder {}

cfg_if::cfg_if! {
    if #[cfg(feature = "navidrome")] {
        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct Indexes {
            #[serde(default)]
            pub index: Vec<IndexId3>,
        }
    } else {
        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct Indexes {
            #[serde(default)]
            pub shortcut: Vec<ArtistId3>,
            #[serde(default)]
            pub index: Vec<Index>,
            #[serde(default)]
            pub child: Vec<Child>,
            pub last_modified: chrono::DateTime<chrono::offset::FixedOffset>,
            pub ignore_articles: String,
        }

        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct Index {
            pub name: String,
            pub artist: Vec<ArtistId3>,
        }
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Directory {
    #[serde(default)]
    pub child: Vec<Child>,
    pub id: String,
    pub parent: Option<String>,
    pub name: String,
    pub starred: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    // #[serde(default, with = "option_user_rating")]
    // pub user_rating: Option<UserRating>,
    pub average_rating: Option<f64>,
    pub play_count: Option<i64>,
}

impl PartialEq for Directory {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for Directory {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Genres {
    pub genre: Vec<Genre>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Genre {
    pub value: String, // TODO check other implementations if it exists there as well
    pub song_count: Option<i32>,
    pub album_count: Option<i32>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct Videos {
    pub video: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct VideoInfo {
    pub id: String,
    #[serde(default)]
    pub captions: Vec<Captions>,
    #[serde(default)]
    pub audio_track: Vec<AudioTrack>,
    #[serde(default)]
    pub conversion: Vec<VideoConversion>,
}

impl PartialEq for VideoInfo {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for VideoInfo {}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Captions {
    pub id: String,
    pub name: Option<String>,
}

impl PartialEq for Captions {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for Captions {}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AudioTrack {
    pub id: String,
    pub name: Option<String>,
    pub language_code: Option<String>,
}

impl PartialEq for AudioTrack {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for AudioTrack {}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct VideoConversion {
    pub id: String,
    pub bit_rate: Option<i32>, // in kbs
    pub audio_track_id: Option<i32>,
}

impl PartialEq for VideoConversion {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for VideoConversion {}

cfg_if::cfg_if! {
    if #[cfg(feature = "navidrome")] {
        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct ArtistInfoBase {
            pub biography: Option<String>,
            pub music_brainz_id: Option<String>,
            pub last_fm_rrl: Option<String>,
            pub small_image_url: Option<String>,
            pub medium_image_url: Option<String>,
            pub large_image_url: Option<String>,
        }
    } else {
        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct ArtistInfoBase {
            #[serde(default)]
            pub biography: Vec<String>,
            #[serde(default)]
            pub music_brainz_id: Vec<String>,
            #[serde(default)]
            pub last_fm_rrl: Vec<String>,
            #[serde(default)]
            pub small_image_url: Vec<String>,
            #[serde(default)]
            pub medium_image_url: Vec<String>,
            #[serde(default)]
            pub large_image_url: Vec<String>,
        }
    }
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ArtistInfo {
    #[serde(flatten)]
    pub base: ArtistInfoBase,
    #[serde(default)]
    pub similar_artist: Vec<Artist>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Artist {
    pub id: String,
    pub name: String,
    pub artist_image_url: Option<String>,
    pub starred: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    #[serde(default, with = "option_user_rating")]
    pub user_rating: Option<UserRating>,
    pub average_rating: Option<f64>,
}

impl PartialEq for Artist {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for Artist {}

cfg_if::cfg_if! {
    if #[cfg(feature = "navidrome")] {
        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct AlbumInfo {
            pub notes: Option<String>,
            pub music_brainz_id: Option<String>,
            pub last_fm_rrl: Option<String>,
            pub small_image_url: Option<String>,
            pub medium_image_url: Option<String>,
            pub large_image_url: Option<String>,
        }
    } else {
        #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
        #[serde(rename_all = "camelCase")]
        pub struct AlbumInfo {
            #[serde(default)]
            pub notes: Vec<String>,
            #[serde(default)]
            pub music_brainz_id: Vec<String>,
            #[serde(default)]
            pub last_fm_rrl: Vec<String>,
            #[serde(default)]
            pub small_image_url: Vec<String>,
            #[serde(default)]
            pub medium_image_url: Vec<String>,
            #[serde(default)]
            pub large_image_url: Vec<String>,
        }
    }
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SimilarSongs {
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TopSongs {
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Songs {
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct NowPlaying {
    #[serde(default)]
    pub entry: Vec<NowPlayingEntry>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct NowPlayingEntry {
    #[serde(flatten)]
    pub child: Child,
    pub username: String, // this is not a typo
    pub minutes_ago: i32,
    pub player_id: i32,
    pub player_name: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Starred {
    #[serde(default)]
    pub artist: Vec<Artist>,
    #[serde(default)]
    pub album: Vec<Child>,
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Starred2 {
    #[serde(default)]
    pub artist: Vec<ArtistId3>,
    #[serde(default)]
    pub album: Vec<AlbumId3>,
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AlbumId3 {
    pub id: String,
    pub name: String,
    pub artist: Option<String>,
    pub artist_id: Option<String>,
    pub cover_art: Option<String>,
    pub song_count: i32,
    pub duration: i32,
    pub play_count: Option<i64>,
    pub created: chrono::DateTime<chrono::offset::FixedOffset>,
    pub starred: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    pub year: Option<i32>,
    pub genre: Option<String>,
    #[serde(default)]
    pub genres: Vec<std::collections::HashMap<String, String>>,
}

impl PartialEq for AlbumId3 {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for AlbumId3 {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SearchResult2 {
    #[serde(default)]
    pub artist: Vec<Artist>,
    #[serde(default)]
    pub album: Vec<Child>,
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SearchResult3 {
    #[serde(default)]
    pub artist: Vec<ArtistId3>,
    #[serde(default)]
    pub album: Vec<AlbumId3>,
    #[serde(default)]
    pub song: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Lyrics {
    pub artist: Option<String>,
    pub title: Option<String>,
    pub value: Option<String>, // maybe navidrome only?
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Shares {
    #[serde(default)]
    pub share: Vec<Share>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Share {
    #[serde(default)]
    pub entry: Vec<Child>,
    pub id: String,
    pub url: String,
    pub description: Option<String>,
    pub username: String,
    pub created: chrono::DateTime<chrono::offset::FixedOffset>,
    pub expires: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    pub last_visited: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
    pub visit_count: i32,
}

impl PartialEq for Share {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for Share {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Podcasts {
    #[serde(default)]
    pub channel: Vec<PodcastChannel>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PodcastChannel {
    #[serde(default)]
    pub episode: Vec<PodcastEpisode>,
    pub id: String,
    pub url: String,
    pub title: Option<String>,
    pub description: Option<String>,
    pub cover_art: Option<String>,
    pub original_image_url: Option<String>,
    pub status: PodcastStatus,
    pub error_message: Option<String>,
}

impl PartialEq for PodcastChannel {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for PodcastChannel {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct NewestPodcasts {
    #[serde(default)]
    pub episode: Vec<PodcastEpisode>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PodcastEpisode {
    #[serde(flatten)]
    pub child: Child,
    pub stream_id: Option<String>,
    pub channel_id: String,
    pub description: Option<String>,
    pub status: PodcastStatus,
    pub publish_date: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct JukeboxStatus {
    pub current_index: i32,
    pub playing: bool,
    pub gain: f32,
    pub position: Option<i32>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct JukeboxPlaylist {
    #[serde(flatten)]
    pub status: JukeboxStatus,
    #[serde(default)]
    pub entry: Vec<Child>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum PodcastStatus {
    New,
    Downloading,
    Completed,
    Error,
    Deleted,
    Skipped,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct InternetRadioStations {
    #[serde(default)]
    pub internet_radio_station: Vec<InternetRadioStation>,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct InternetRadioStation {
    pub id: String,
    pub name: String,
    pub stream_url: String,
    pub home_page_url: Option<String>,
}

impl PartialEq for InternetRadioStation {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}
impl Eq for InternetRadioStation {}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ChatMessages {
    #[serde(default)]
    pub chat_message: Vec<ChatMessage>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ChatMessage {
    pub username: String,
    pub time: i64,
    pub message: String,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Users {
    #[serde(default)]
    pub user: Vec<User>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct User {
    #[serde(default)]
    pub folder: Vec<i32>,
    pub username: String,
    pub email: Option<String>,
    pub scrobbling_enabled: bool,
    pub max_bit_rate: Option<i32>,
    pub admin_role: bool,
    pub settings_role: bool,
    pub download_role: bool,
    pub upload_role: bool,
    pub playlist_role: bool,
    pub cover_art_role: bool,
    pub comment_role: bool,
    pub podcast_role: bool,
    pub stream_role: bool,
    pub jukebox_role: bool,
    pub video_conversion_role: bool,
    pub avatar_last_changed: Option<chrono::DateTime<chrono::offset::FixedOffset>>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Bookmarks {
    #[serde(default)]
    pub bookmark: Vec<Bookmark>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Bookmark {
    pub entry: Child,
    pub position: i64,
    pub username: String,
    pub comment: Option<String>,
    pub created: chrono::DateTime<chrono::offset::FixedOffset>,
    pub changed: chrono::DateTime<chrono::offset::FixedOffset>,
}

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PlayQueue {
    #[serde(default)]
    pub entry: Vec<Child>,
    pub current: Option<String>, // current playing track, TODO check if reference is wrong
    pub position: Option<i64>,   // in ms
    pub username: String,
    pub changed: chrono::DateTime<chrono::offset::FixedOffset>,
    pub changed_by: String, // client name
}

mod status {
    use super::Status;
    use serde::{self, Deserialize, Deserializer};

    pub fn deserialize<'de, D>(deserializer: D) -> Result<Status, D::Error>
    where
        D: Deserializer<'de>,
    {
        let s: Option<&str> = Option::deserialize(deserializer)?;
        match s {
            Some("ok") => Ok(Status::Ok),
            Some("failed") => Ok(Status::Error),
            _ => Ok(Status::Error),
        }
    }
}

mod option_user_rating {
    use crate::data::UserRating;
    use serde::{self, Deserialize, Deserializer, Serializer};

    pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<UserRating>, D::Error>
    where
        D: Deserializer<'de>,
    {
        let s: Option<i32> = Option::deserialize(deserializer)?;
        match s {
            Some(1) => Ok(Some(UserRating::One)),
            Some(2) => Ok(Some(UserRating::Two)),
            Some(3) => Ok(Some(UserRating::Three)),
            Some(4) => Ok(Some(UserRating::Four)),
            Some(5) => Ok(Some(UserRating::Five)),
            _ => Ok(None),
        }
    }

    pub fn serialize<S>(value: &Option<UserRating>, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let number = match value {
            None => return serializer.serialize_none(),
            Some(UserRating::One) => 1,
            Some(UserRating::Two) => 2,
            Some(UserRating::Three) => 3,
            Some(UserRating::Four) => 4,
            Some(UserRating::Five) => 5,
        };
        serializer.serialize_i32(number)
    }
}