//! The [`Node`] component: per-entity scene metadata.

use serde::{Deserialize, Serialize};

/// Metadata attached to every entity that participates in the scene graph.
///
/// A `Node` carries the human-facing identity of an entity (its `name`, shown
/// in the editor hierarchy) and an `enabled` flag. Disabling a node is a
/// declaration of intent that later systems honor — rendering, physics, and
/// audio skip disabled subtrees — but it does **not** affect transform
/// resolution, which is purely geometric. Stage 3 only stores and edits the
/// flag; the systems that act on it arrive in later stages.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, crate::reflect::Reflect)]
pub struct Node {
    /// Display name. Need not be unique; entities are identified by their
    /// [`Entity`](hecs::Entity) handle, not by name.
    pub name: String,
    /// Whether this node (and, by convention, its subtree) is active.
    pub enabled: bool,
}

impl Node {
    /// Creates an enabled node with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            enabled: true,
        }
    }
}

impl Default for Node {
    /// An enabled, unnamed node.
    fn default() -> Self {
        Self {
            name: String::new(),
            enabled: true,
        }
    }
}

impl<T: Into<String>> From<T> for Node {
    fn from(name: T) -> Self {
        Self::new(name)
    }
}
