use std::path::Path;
use log::info;
use crate::service::macos::OSXServiceManager;
use crate::service::runit::RunitServiceManager;
use crate::service::ServiceManager;
use crate::service::systemd::SystemDServiceManager;
use crate::service::windows::WindowsServiceManager;

pub fn detect_service() -> Option<Box<dyn ServiceManager>> {
    if cfg!(windows) {
        return Some(Box::new(WindowsServiceManager {}));
    }
    if cfg!(macos) {
        return Some(Box::new(OSXServiceManager {}));
    }
    detect_unix_service_manager()
}

pub fn detect_unix_service_manager() -> Option<Box<dyn ServiceManager>> {
    if Path::new("/etc/runit/1").exists() {
        info!("Detected Runit service supervision (confidence: 100%, /etc/runit/1 exists)");
        return Some(Box::new(RunitServiceManager {}))
    }
    if Path::new("/var/lib/systemd").exists() {
        info!("Detected SystemD service supervision (confidence: 100%, /var/lib/systemd exists)");
        return Some(Box::new(SystemDServiceManager {}));
    }
    None
}