use crate::core::{AnimationClip, Skeleton, TransformTrack, Keyframe, InterpolationMode};
use crate::error::Result;
use glam::{Mat4, Vec3};
use std::collections::HashMap;

/// Create a test skeleton (simple humanoid)
pub fn create_test_skeleton() -> Skeleton {
    let mut skeleton = Skeleton::new();
    
    // Root
    skeleton.add_bone("Root".to_string(), None, Mat4::IDENTITY);
    
    // Hips (child of Root)
    skeleton.add_bone("Hips".to_string(), Some(0), Mat4::IDENTITY);
    
    // Spine (child of Hips)
    skeleton.add_bone("Spine".to_string(), Some(1), Mat4::IDENTITY);
    
    // Legs (children of Hips)
    skeleton.add_bone("LeftLeg".to_string(), Some(1), Mat4::IDENTITY);
    skeleton.add_bone("RightLeg".to_string(), Some(1), Mat4::IDENTITY);
    
    skeleton
}

/// Create a test walk animation
pub fn create_test_walk_clip() -> Result<AnimationClip> {
    let mut bone_tracks = HashMap::new();
    
    // Animate Hips with bobbing motion
    let mut hips_track = TransformTrack::new();
    hips_track.positions = vec![
        Keyframe {
            time: 0.0,
            value: Vec3::new(0.0, 0.0, 0.0),
            interpolation: InterpolationMode::Linear,
        },
        Keyframe {
            time: 0.5,
            value: Vec3::new(0.0, 0.1, 0.0), // Bob up
            interpolation: InterpolationMode::Linear,
        },
        Keyframe {
            time: 1.0,
            value: Vec3::new(0.0, 0.0, 0.0),
            interpolation: InterpolationMode::Linear,
        },
    ];
    bone_tracks.insert("Hips".to_string(), hips_track);
    
    AnimationClip::new("Walk".to_string(), 1.0, bone_tracks)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_skeleton_is_valid() {
        let skeleton = create_test_skeleton();
        assert!(skeleton.validate().is_ok());
        assert_eq!(skeleton.bones.len(), 5);
    }
    
    #[test]
    fn test_walk_clip_loads() {
        let clip = create_test_walk_clip().unwrap();
        assert_eq!(clip.name, "Walk");
        assert_eq!(clip.duration, 1.0);
    }
}
