use anyhow::Result;
use notify_rust::Notification;

pub struct NotificationManager {
    app_name: String,
}

impl NotificationManager {
    pub fn new() -> Self {
        #[cfg(target_os = "macos")]
        let app_name = "com.apple.terminal";
        notify_rust::set_application(&app_name);

        Self {
            app_name: app_name.to_string(),
        }
    }

    pub fn send(&self, title: &str, body: &str) -> notify_rust::error::Result<()> {
        Notification::new()
            .summary(title)
            .body(body)
            .appname(&self.app_name)
            .show()?;
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_send_notification() -> Result<()> {
        let notification_manager = NotificationManager::new();
        notification_manager.send("Test", "This is a test notification")?;
        Ok(())
    }
}
