//! This module contains the macros used in the project

/// automatically generate the input path
macro_rules! config_path {
    ($config:ident, $setting_name: ident, $struct_name: ident, $key_name: ident, $string: expr) => {
        match &$config.config_data.$setting_name {
            Some($struct_name {
                $key_name: Some(path),
                ..
            }) => PathBuf::from(path),
            _ => {
                println!(concat!(
                    "Please enter the path to the folder where to save ",
                    $string,
                    ":"
                ));
                let (file_path, path_string) = input_path()?;
                $config.update(|config_data| {
                    if let Some(local_config) = config_data.$setting_name.as_mut() {
                        local_config.$key_name = Some(path_string);
                    } else {
                        config_data.$setting_name = Some($struct_name {
                            $key_name: Some(path_string),
                            ..Default::default()
                        });
                    }
                })?;
                file_path
            }
        }
    };
}

pub(crate) use config_path;
/// automatically get the input path
macro_rules! get_config_path {
    ($config:ident, $setting_name: ident, $struct_name: ident, $key_name: ident, $string: expr) => {
        match &$config.config_data.$setting_name {
            Some($struct_name {
                $key_name: Some(path),
                ..
            }) => Ok(PathBuf::from(path)),
            _ => Err(GeneralError::new(concat!(
                "The path ",
                $string,
                " is not set"
            ))),
        }
    };
}
pub(crate) use get_config_path;
