use serde::{Deserialize, Serialize};

use super::{BlockId, Story, TextSpan};

/// A normalized textual unit extracted from a DOCX story.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Block {
    /// Stable identifier for this block.
    pub id: BlockId,
    /// The story this block belongs to.
    pub story: Story,
    /// Semantic kind of block.
    pub kind: BlockKind,
    /// Current-view text content for this block.
    pub text: String,
    /// Optional style name when mapped by the extractor.
    pub style: Option<String>,
    /// Optional tracked-change markers aligned to visible text.
    pub text_spans: Option<Vec<TextSpan>>,
    /// Referenced footnote ids that appear inline in this block.
    pub footnote_refs: Vec<u32>,
    /// Referenced endnote ids that appear inline in this block.
    pub endnote_refs: Vec<u32>,
}

/// Semantic classification of a block.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum BlockKind {
    /// A regular paragraph block.
    Paragraph,
    /// A heading with extracted level information.
    Heading { level: u8 },
    /// A list item with extracted nesting level.
    ListItem { level: usize },
    /// A flat table-cell block in the extracted output.
    TableCell {
        /// Identifier shared by cells that belong to the same table.
        table_id: String,
        /// Zero-based row index.
        row: usize,
        /// Zero-based column index.
        col: usize,
    },
}
