1
use std::collections::HashMap;
2

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

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

            
10
empty_command_request!(Config, "config");
11

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

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

            
29
impl CommandResponse for ConfigResponse {
30
    type Request = ConfigRequest;
31

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

            
35
        let music_directory = get_property!(parts, "music_directory", Text).to_string();
36
        let playlist_directory = get_property!(parts, "playlist_directory", Text).to_string();
37

            
38
        // TODO: is this parsed correctly?
39
        let pcre = get_and_parse_property!(parts, "pcre", Text);
40

            
41
        Ok(ConfigResponse {
42
            music_directory,
43
            playlist_directory,
44
            pcre,
45
        })
46
    }
47

            
48
    fn serialize(&self) -> Vec<u8> {
49
        unimplemented!("response serialization is not yet implemented for ConfigResponse")
50
    }
51
}