use std::sync::OnceLock;
use systemprompt_identifiers::UserId;
use systemprompt_models::services::SystemAdmin;
use thiserror::Error;
static PLATFORM_OWNER: OnceLock<SystemAdmin> = OnceLock::new();
pub fn install_log_attribution(admin: SystemAdmin) -> &'static SystemAdmin {
PLATFORM_OWNER.get_or_init(|| admin)
}
pub fn platform_attribution() -> Result<&'static SystemAdmin, LogAttributionUnset> {
PLATFORM_OWNER.get().ok_or(LogAttributionUnset)
}
pub(crate) fn platform_owner_id() -> Result<&'static UserId, LogAttributionUnset> {
platform_attribution().map(SystemAdmin::id)
}
#[derive(Debug, Clone, Copy, Error)]
#[error("log attribution not installed: AppContext bootstrap must run before platform log events")]
pub struct LogAttributionUnset;