use serde::{Deserialize, Serialize};

use super::ChangeId;

/// A visible text fragment within a block.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TextSpan {
    /// Visible text contained in this span.
    pub text: String,
    /// Tracked-change markers that apply to this span.
    pub tracked_changes: Vec<SpanTrackedChange>,
}

/// A tracked-change marker attached to a [`TextSpan`].
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SpanTrackedChange {
    /// Identifier of the referenced tracked change.
    pub id: ChangeId,
    /// Kind of span-level change marker.
    pub kind: SpanChangeKind,
}

/// Span-level view of tracked changes affecting visible text.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum SpanChangeKind {
    /// Inserted visible text.
    Insert,
    /// Deleted text marker.
    Delete,
    /// Replacement marker after pairing.
    Replacement,
    /// Move-from marker.
    MoveFrom,
    /// Move-to marker.
    MoveTo,
    /// Formatting change marker.
    Format,
}
