1
use std::collections::HashMap;
2

            
3
use serde::{Deserialize, Serialize};
4

            
5
use crate::{
6
    commands::{Command, CommandResponse, ResponseParserError, empty_command_request},
7
    response_tokenizer::{ResponseAttributes, get_and_parse_property, get_property},
8
};
9

            
10
pub struct Config;
11

            
12
empty_command_request!(Config, "config");
13

            
14
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15
pub struct ConfigResponse {
16
    pub music_directory: String,
17
    pub playlist_directory: String,
18
    pub pcre: bool,
19
}
20

            
21
impl ConfigResponse {
22
    pub fn new(music_directory: String, playlist_directory: String, pcre: bool) -> Self {
23
        ConfigResponse {
24
            music_directory,
25
            playlist_directory,
26
            pcre,
27
        }
28
    }
29
}
30

            
31
impl CommandResponse for ConfigResponse {
32
    fn into_response_enum(self) -> crate::Response {
33
        todo!()
34
    }
35

            
36
    fn from_response_enum(_response: crate::Response) -> Option<Self> {
37
        todo!()
38
    }
39

            
40
    fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
41
        let parts: HashMap<_, _> = parts.into_map()?;
42

            
43
        let music_directory = get_property!(parts, "music_directory", Text).to_string();
44
        let playlist_directory = get_property!(parts, "playlist_directory", Text).to_string();
45

            
46
        // TODO: is this parsed correctly?
47
        let pcre = get_and_parse_property!(parts, "pcre", Text);
48

            
49
        Ok(ConfigResponse {
50
            music_directory,
51
            playlist_directory,
52
            pcre,
53
        })
54
    }
55
}
56

            
57
impl Command for Config {
58
    type Request = ConfigRequest;
59
    type Response = ConfigResponse;
60
}