use crate::ecs::systems::{
    JointUploadSystem, animation_blending_system, animation_sampling_system,
    skinning_palette_system, transform_hierarchy_system,
};
use archetype_ecs::World;
use archetype_ecs::system::System;

/// Production-grade animation pipeline
///
/// Orchestrates the animation update flow in the correct order:
/// 1. Sampling & Blending (Local transforms)
/// 2. Hierarchy Propagation (Local -> Global transforms)
/// 3. Skinning Palette Calculation (Global transforms -> Joint matrices)
/// 4. Joint Upload (Joint matrices -> GPU)
pub struct AnimationPipeline;

impl AnimationPipeline {
    /// Update the animation state for the entire world
    pub fn update(world: &mut World, dt: f32) {
        // 1. Sample animations (updates LocalTransform)
        animation_sampling_system(world, dt);

        // 2. Blend animations (updates LocalTransform)
        // Note: Blending currently runs its own sampling/logic
        animation_blending_system(world, dt);

        // 3. Propagate transforms (Local -> Global)
        transform_hierarchy_system(world);

        // 4. Compute skinning palette (Global -> Matrices)
        skinning_palette_system(world);

        // 5. Upload joint matrices to GPU
        let mut upload = JointUploadSystem;
        let _ = upload.run(world);
    }
}
