use freecs::Entity;

/// Establishes a parent-child hierarchy relationship.
///
/// When an entity has a [`Parent`], its [`super::LocalTransform`] is relative to
/// the parent's world-space transform. The transform propagation system computes
/// [`super::GlobalTransform`] by multiplying transforms up the hierarchy.
///
/// Use `Parent(None)` to explicitly mark an entity as a root (equivalent to no Parent component).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
pub struct Parent(pub Option<Entity>);

impl enum2schema::Schema for Parent {
    fn schema() -> enum2schema::serde_json::Value {
        enum2schema::nullable(enum2schema::serde_json::json!({
            "type": "object",
            "properties": {
                "id": { "type": "integer" },
                "generation": { "type": "integer" }
            },
            "required": ["id", "generation"]
        }))
    }
}
