#![deny(missing_debug_implementations)]

/// Version of the Rust core linked into platform shells.
pub fn version() -> &'static str {
    env!("CARGO_PKG_VERSION")
}

/// Platform family reported by the current Rust target.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlatformFamily {
    Android,
    Apple,
    Linux,
    Windows,
    Other,
}

impl PlatformFamily {
    pub fn current() -> Self {
        if cfg!(target_os = "android") {
            Self::Android
        } else if cfg!(target_vendor = "apple") {
            Self::Apple
        } else if cfg!(target_os = "linux") {
            Self::Linux
        } else if cfg!(target_os = "windows") {
            Self::Windows
        } else {
            Self::Other
        }
    }

    pub fn as_str(self) -> &'static str {
        match self {
            Self::Android => "android",
            Self::Apple => "apple",
            Self::Linux => "linux",
            Self::Windows => "windows",
            Self::Other => "other",
        }
    }
}

/// Human-readable core identity for stubs and smoke tests.
pub fn identity() -> String {
    format!(
        "burrow-core/{} ({})",
        version(),
        PlatformFamily::current().as_str()
    )
}

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

    #[test]
    fn identity_includes_project_name() {
        assert!(identity().starts_with("burrow-core/"));
    }
}
