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

            
9
pub struct PlaylistSearch;
10

            
11
impl Command for PlaylistSearch {
12
    type Response = ();
13
    const COMMAND: &'static str = "playlistsearch";
14

            
15
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
16
        let filter = parse_filter(&mut parts)?;
17

            
18
        let mut sort_or_window = parts.next();
19
        let mut sort = None;
20
        if let Some("sort") = sort_or_window {
21
            sort = Some(
22
                parts
23
                    .next()
24
                    .ok_or(RequestParserError::UnexpectedEOF)?
25
                    .to_string(),
26
            );
27
            sort_or_window = parts.next();
28
        }
29

            
30
        let mut window = None;
31
        if let Some("window") = sort_or_window {
32
            let w = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
33
            window = Some(
34
                w.parse()
35
                    .map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))?,
36
            );
37
        }
38

            
39
        debug_assert!(parts.next().is_none());
40

            
41
        Ok((Request::PlaylistSearch(filter, sort, window), ""))
42
    }
43

            
44
    fn parse_response(
45
        _parts: ResponseAttributes<'_>,
46
    ) -> Result<Self::Response, ResponseParserError> {
47
        unimplemented!()
48
    }
49
}