1
use crate::commands::{
2
    Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
3
    ResponseParserError,
4
};
5

            
6
pub struct StickerNames;
7

            
8
pub type StickerNamesResponse = Vec<String>;
9

            
10
impl Command for StickerNames {
11
    type Response = StickerNamesResponse;
12
    const COMMAND: &'static str = "stickernames";
13

            
14
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
15
        debug_assert!(parts.next().is_none());
16

            
17
        Ok((Request::StickerNames, ""))
18
    }
19

            
20
    fn parse_response(
21
        parts: ResponseAttributes<'_>,
22
    ) -> Result<Self::Response, ResponseParserError> {
23
        debug_assert!(parts.0.iter().all(|(k, _)| *k == "name"));
24

            
25
        let list = parts
26
            .0
27
            .iter()
28
            .map(|(_, v)| match v {
29
                GenericResponseValue::Text(value) => Ok(value.to_string()),
30
                GenericResponseValue::Binary(_) => Err(
31
                    ResponseParserError::UnexpectedPropertyType("name", "Binary"),
32
                ),
33
            })
34
            .collect::<Result<Vec<_>, ResponseParserError>>()?;
35

            
36
        Ok(list)
37
    }
38
}