use config::{ConfigError, Config};
use std::collections::HashMap;

#[derive(Debug, Deserialize)]
pub struct EmailCredentials {
    pub smtp_server: String,
    pub smtp_name: String,
    pub smtp_username: String,
    pub smtp_password: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct EmailStrings {
    pub subject: String,
    pub message: String,
    pub attachment: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FormStrings {
    pub title: String,
    pub h1: String,
    pub h2: String,
    pub name: String,
    pub email: String,
    pub num_guests: String,
    pub cant_come: String,
    pub one_guest: String,
    pub two_guest: String,
    pub three_guest: String,
    pub four_guest: String,
    pub five_guest: String,
    pub submit: String,
    pub additional_info: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageStrings {
    pub title: String,
    pub h1: String,
    pub message: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct LanguageStrings {
    pub email: EmailStrings,
    pub form: FormStrings,
    pub thanks: MessageStrings,
    pub spam:MessageStrings, 
}

#[derive(Debug, Deserialize)]
pub struct Settings {
    pub email_credentials: EmailCredentials,
    pub spam_wait: u64,
    pub tld_mapping: HashMap<String, String>,
    pub default_lang: String,
    pub languages: HashMap<String, LanguageStrings>,
}

impl Settings {
    pub fn new() -> Result<Self,ConfigError> {
    let mut settings = Config::default();
    settings
        // File::with_name(..) is shorthand for File::from(Path::new(..))
        .merge(config::File::with_name("config.hjson")).unwrap();


    settings.try_into()
    }

}
