1
use crate::{
2
    commands::{
3
        Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
4
        ResponseParserError,
5
    },
6
    filter::parse_filter,
7
};
8

            
9
pub struct SearchAddPl;
10

            
11
pub struct SearchAddPlResponse {}
12

            
13
impl Command for SearchAddPl {
14
    type Response = SearchAddPlResponse;
15
    const COMMAND: &'static str = "searchaddpl";
16

            
17
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
18
        let playlist_name = parts
19
            .next()
20
            .ok_or(RequestParserError::UnexpectedEOF)?
21
            .to_string();
22

            
23
        let filter = parse_filter(&mut parts)?;
24

            
25
        let mut sort_or_window_or_position = parts.next();
26
        let mut sort = None;
27
        if let Some("sort") = sort_or_window_or_position {
28
            sort = Some(
29
                parts
30
                    .next()
31
                    .ok_or(RequestParserError::UnexpectedEOF)?
32
                    .to_string(),
33
            );
34
            sort_or_window_or_position = parts.next();
35
        }
36

            
37
        let mut window = None;
38
        if let Some("window") = sort_or_window_or_position {
39
            let w = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
40
            window = Some(
41
                w.parse()
42
                    .map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))?,
43
            );
44
            sort_or_window_or_position = parts.next();
45
        }
46

            
47
        let mut position = None;
48
        if let Some("position") = sort_or_window_or_position {
49
            let p = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
50
            position = Some(
51
                p.parse()
52
                    .map_err(|_| RequestParserError::SyntaxError(0, p.to_string()))?,
53
            );
54
        }
55

            
56
        debug_assert!(parts.next().is_none());
57

            
58
        Ok((
59
            Request::SearchAddPl(playlist_name, filter, sort, window, position),
60
            "",
61
        ))
62
    }
63

            
64
    fn parse_response(
65
        parts: ResponseAttributes<'_>,
66
    ) -> Result<Self::Response, ResponseParserError> {
67
        unimplemented!()
68
    }
69
}