use nodedb_types::Surrogate;
use super::pk::{TargetPk, extract_pk_value};
pub(crate) fn derive_document_id(
target_pk: &TargetPk,
body: &[u8],
surrogate: Surrogate,
) -> String {
match target_pk {
TargetPk::AutoRowId => surrogate.as_u32().to_string(),
TargetPk::Field(field) => {
extract_pk_value(body, field).unwrap_or_else(|| surrogate.as_u32().to_string())
}
}
}
pub(crate) fn require_surrogate(
surrogate_u32: Option<u32>,
doc_id: &str,
op_label: &str,
) -> crate::Result<Surrogate> {
match surrogate_u32 {
Some(s) => Ok(Surrogate::new(s)),
None => Err(crate::Error::PlanError {
detail: format!(
"{op_label} target row '{doc_id}' lacks a surrogate; \
collection is not surrogate-keyed"
),
}),
}
}