vstorage 0.7.0

Common API for various icalendar/vcard storages.
Documentation
// Copyright 2023-2026 Hugo Osvaldo Barrera
//
// SPDX-License-Identifier: EUPL-1.2

//! Synchronisation policies for deciding what operations to perform.
//!
//! The [`Mode`] trait and its implementations decide what synchronisation operations to
//! perform based on detected state changes.

use std::sync::Arc;

use super::{
    analysis::{ItemAnalysis, PropertyChange, ResolvedMapping},
    operation::{ItemOp, MappingUidSource, PropertyOp},
    ordering::DeletionBarrier,
    status::MappingUid,
};

/// Mode of operation for deciding which synchronisation operations to perform.
///
/// Separates the decision-making logic from state comparison. Different implementations can
/// provide different synchronisation behaviors (two-way, one-way, etc.).
pub trait Mode: Send + Sync {
    /// Decide which item operation to perform based on analysed item state.
    ///
    /// Returns `None` if no operation is needed.
    fn decide_item_action(
        &self,
        analysis: ItemAnalysis,
        mapping: &Arc<ResolvedMapping>,
        mapping_uid_source: MappingUidSource,
        on_complete: Option<&DeletionBarrier>,
    ) -> Option<ItemOp>;

    /// Decide which property operation to perform based on detected change.
    ///
    /// Returns `None` if no operation is needed.
    fn decide_property_action(
        &self,
        change: PropertyChange,
        mapping: &Arc<ResolvedMapping>,
        mapping_uid: MappingUid,
        on_complete: Option<&DeletionBarrier>,
    ) -> Option<PropertyOp>;
}