//! apt-ostreed daemon main entry point

use apt_ostree::daemon::{DaemonDBus, DaemonConfig};
use zbus::ConnectionBuilder;
use tracing::{info, Level};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize logging
    tracing_subscriber::fmt()
        .with_max_level(Level::INFO)
        .init();

    info!("Starting apt-ostreed daemon...");

    // Load configuration
    let config = DaemonConfig::default();
    info!("Using configuration: {:?}", config);

    // Create daemon instance
    let daemon = DaemonDBus::new(config)?;
    info!("Daemon instance created successfully");

    // Create DBus connection
    let _connection = ConnectionBuilder::system()?
        .name("org.projectatomic.aptostree1")?
        .serve_at("/org/projectatomic/aptostree1", daemon)?
        .build()
        .await?;

    info!("DBus connection established successfully");
    info!("Daemon is now running on system bus");

    // Keep the connection alive
    loop {
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    }
}
