use serde::Deserialize;

#[derive(Debug, Deserialize, Clone)]
pub struct EmailConfig {
    #[serde(default)]
    pub enabled: bool,
    #[serde(default)]
    pub smtp_host: String,
    #[serde(default = "default_smtp_port")]
    pub smtp_port: u16,
    #[serde(default)]
    pub smtp_username: String,
    #[serde(default)]
    pub smtp_password: String,
    #[serde(default)]
    pub from_email: String,
    #[serde(default = "default_from_name")]
    pub from_name: String,
    #[serde(default = "default_code_ttl")]
    pub verification_code_ttl_seconds: u64,
    #[serde(default)]
    pub queue_enabled: bool,
    #[serde(default = "default_worker_pool_size")]
    pub worker_pool_size: usize,
}

fn default_smtp_port() -> u16 {
    587
}
fn default_from_name() -> String {
    "Email Unlimited".into()
}
fn default_code_ttl() -> u64 {
    600
}
fn default_worker_pool_size() -> usize {
    2
}

impl Default for EmailConfig {
    fn default() -> Self {
        Self {
            enabled: false,
            smtp_host: String::new(),
            smtp_port: default_smtp_port(),
            smtp_username: String::new(),
            smtp_password: String::new(),
            from_email: String::new(),
            from_name: default_from_name(),
            verification_code_ttl_seconds: default_code_ttl(),
            queue_enabled: false,
            worker_pool_size: default_worker_pool_size(),
        }
    }
}
