use derive_more::{AsMut, AsRef, Debug, Deref, DerefMut};
use sled::InlineArray;

use crate::{Entry, Record};

#[derive(Debug, Clone, AsMut, AsRef, Deref, DerefMut)]
pub struct Updater<Item: Record> {
    pub id: Item::SelfId,
    #[deref]
    #[deref_mut]
    #[as_ref]
    #[as_mut]
    pub val: Item,
    /// save bytes for old value
    #[debug(skip)]
    pub bytes: InlineArray,
    pub old: Item,
}

impl<Item: Record> From<Updater<Item>> for Entry<Item> {
    fn from(value: Updater<Item>) -> Self {
        Entry::new(value.id, value.val)
    }
}
