use std::fmt;
use std::io;
use std::path::PathBuf;
use crate::servers::ServerConfig;
use crate::util::LoggingConfig;
use crate::wallet::WalletConfig;
#[derive(Debug)]
pub enum ConfigError {
ParseError(String, String),
FileIOError(String, String),
FileNotFoundError(String),
SerializationError(String),
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ConfigError::ParseError(ref file_name, ref message) => write!(
f,
"Error parsing configuration file at {} - {}",
file_name, message
),
ConfigError::FileIOError(ref file_name, ref message) => {
write!(f, "{} {}", message, file_name)
}
ConfigError::FileNotFoundError(ref file_name) => {
write!(f, "Configuration file not found: {}", file_name)
}
ConfigError::SerializationError(ref message) => {
write!(f, "Error serializing configuration: {}", message)
}
}
}
}
impl From<io::Error> for ConfigError {
fn from(error: io::Error) -> ConfigError {
ConfigError::FileIOError(
String::from(""),
String::from(format!("Error loading config file: {}", error)),
)
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct GlobalConfig {
pub config_file_path: Option<PathBuf>,
pub members: Option<ConfigMembers>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ConfigMembers {
#[serde(default)]
pub server: ServerConfig,
pub logging: Option<LoggingConfig>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct GlobalWalletConfig {
pub config_file_path: Option<PathBuf>,
pub members: Option<GlobalWalletConfigMembers>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct GlobalWalletConfigMembers {
#[serde(default)]
pub wallet: WalletConfig,
pub logging: Option<LoggingConfig>,
}