use crate::lst_parser::syntax_kind::SyntaxKind;

use super::error::SyntaxError;

#[derive(Debug)]
pub enum Event {
    Start {
        kind: NodeKind,
        forward_parent: Option<usize>,
    },
    Finish,
    Eat {
        count: usize,
    },
}

#[derive(Debug, Clone, PartialEq)]
pub enum NodeKind {
    Syntax(SyntaxKind),
    Error(SyntaxError),
}

impl NodeKind {
    pub fn is_syntax(&self) -> bool {
        matches!(self, Self::Syntax(_))
    }

    pub fn is_error(&self) -> bool {
        matches!(self, Self::Error(_))
    }
}

impl From<SyntaxKind> for NodeKind {
    fn from(value: SyntaxKind) -> Self {
        NodeKind::Syntax(value)
    }
}

impl From<SyntaxError> for NodeKind {
    fn from(value: SyntaxError) -> Self {
        NodeKind::Error(value)
    }
}

impl PartialEq<SyntaxKind> for NodeKind {
    fn eq(&self, other: &SyntaxKind) -> bool {
        match self {
            NodeKind::Syntax(s) => s == other,
            NodeKind::Error(_) => false,
        }
    }
}

impl PartialEq<SyntaxError> for NodeKind {
    fn eq(&self, other: &SyntaxError) -> bool {
        match self {
            NodeKind::Syntax(_) => false,
            NodeKind::Error(e) => e == other,
        }
    }
}

impl Event {
    pub(crate) fn tombstone() -> Self {
        Self::Start {
            kind: SyntaxKind::TOMBSTONE.into(),
            forward_parent: None,
        }
    }
}
