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
use super::types::{message::Text, number::Number};

#[derive(Debug)]
pub enum UidlResponse {
    Multiple(Uidl),
    Single(UniqueId),
}

impl From<Uidl> for UidlResponse {
    fn from(value: Uidl) -> Self {
        Self::Multiple(value)
    }
}

impl From<UniqueId> for UidlResponse {
    fn from(value: UniqueId) -> Self {
        Self::Single(value)
    }
}

#[derive(Debug)]
pub struct Uidl {
    message: Option<Text>,
    items: Vec<UniqueId>,
}

impl Uidl {
    pub fn new<M: Into<Text>>(message: Option<M>, items: Vec<UniqueId>) -> Self {
        Self {
            message: message.map(|msg| msg.into()),
            items,
        }
    }

    pub fn items(&self) -> &[UniqueId] {
        self.items.as_ref()
    }

    pub fn message(&self) -> Option<&Text> {
        self.message.as_ref()
    }
}

#[derive(Debug)]
pub struct UniqueId {
    index: Number,
    id: Text,
}

impl UniqueId {
    pub fn new<I: Into<Number>, D: Into<Text>>(index: I, id: D) -> Self {
        Self {
            index: index.into(),
            id: id.into(),
        }
    }

    pub fn index(&self) -> &Number {
        &self.index
    }

    pub fn id(&self) -> &Text {
        &self.id
    }
}