//! Browser-generic navigation history data models.

/// An opaque identifier for a navigation history entry.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NavigationEntryId(pub u64);

impl NavigationEntryId {
    /// Create a new identifier from a raw numeric value.
    pub const fn new(raw: u64) -> Self {
        Self(raw)
    }

    /// Get the raw numeric value of this identifier.
    pub const fn get(self) -> u64 {
        self.0
    }
}

impl std::fmt::Display for NavigationEntryId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.get())
    }
}

/// History entry metadata visible to the host.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NavigationHistoryEntry {
    pub entry_id: NavigationEntryId,
    pub url: String,
    pub title: Option<String>,
    pub index: usize,
    /// True when this entry belongs to the same document as the previous entry.
    pub same_document_with_previous: bool,
}

/// Snapshot of the current navigation history for a browsing context.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NavigationHistorySnapshot {
    pub request_id: u64,
    pub current_entry_id: NavigationEntryId,
    pub current_index: usize,
    pub entries: Vec<NavigationHistoryEntry>,
}

/// Classification of the navigation that produced a state update.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NavigationKind {
    NewDocument,
    SameDocument,
    SameDocumentReplace,
    HistoryTraversal,
    Reload,
}
