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
// use lunar_lib::database::{Db, Entry, TransactionError};
// use serde::{Deserialize, Serialize};
// use crate::{
// database::Library,
// library::{
// collectable::Collectable,
// collection::rules::{AlbumRule, RuleGroup, TrackRule},
// image_art::ImageArt,
// },
// };
// mod frontend_impls;
// pub mod trait_impls;
// #[cfg(feature = "stable-abi")]
// mod sdk_impls;
// pub mod rules;
// #[derive(Debug, thiserror::Error)]
// pub enum CollectionCreationError {
// #[error("Collection name resolved to an empty string")]
// EmptyName,
// #[error("Collection name resolved to a reserved collection name")]
// ReservedName(String),
// }
// #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
// pub enum CollectionItems {
// Static { collectables: Vec<Collectable> },
// Dynamic { rules: Vec<DynamicCollectionRules> },
// }
// impl CollectionItems {
// pub fn resolve(self, db: &Db<Library>) -> Result<Vec<Collectable>, TransactionError> {
// match self {
// CollectionItems::Static { collectables } => Ok(collectables),
// CollectionItems::Dynamic { rules } => Ok(resolve_rules(&rules, db)?),
// }
// }
// }
// #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
// pub enum DynamicCollectionRules {
// Track(RuleGroup<TrackRule>),
// Album(RuleGroup<AlbumRule>),
// }
// #[derive(Debug, Clone, Serialize, Deserialize)]
// pub struct Collection {
// pub name: String,
// pub cover_art: Option<ImageArt>,
// pub items: CollectionItems,
// read_only: bool,
// }
// impl Collection {
// /// Creates a new static collection with the input name
// ///
// /// # Errors
// ///
// /// This function will return `None` if the input name is empty or is trimmed to an empty string
// fn new_static(name: impl AsRef<str>) -> Result<Self, CollectionCreationError> {
// let name = name.as_ref().trim();
// if name.is_empty() {
// return Err(CollectionCreationError::EmptyName);
// }
// Ok(Self {
// name: name.to_owned(),
// cover_art: None,
// items: CollectionItems::Static {
// collectables: Vec::new(),
// },
// read_only: false,
// })
// }
// }
// pub fn resolve_rules(
// rules: &[DynamicCollectionRules],
// db: &Db<Library>,
// ) -> Result<Vec<Collectable>, TransactionError> {
// let tracks = Entry::db_get_all(db)?;
// let albums = Entry::db_get_all(db)?;
// let mut collectables = Vec::new();
// for group in rules {
// match group {
// DynamicCollectionRules::Track(rule_group) => {
// let tracks = rule_group.filter(&tracks);
// collectables.extend(tracks.map(|t| Collectable::Track(t.id())));
// }
// DynamicCollectionRules::Album(rule_group) => {
// let albums = rule_group.filter(&albums);
// collectables.extend(albums.map(|t| Collectable::Album(t.id())));
// }
// }
// }
// Ok(collectables)
// }