use crate::core::{AnimationClip, Skeleton};
use crate::ecs::components::{AnimationClipHandle, SkeletonHandle};
use std::collections::HashMap;

/// Global storage for skeleton assets
#[derive(Clone)]
pub struct SkeletonAssets {
    skeletons: HashMap<SkeletonHandle, Skeleton>,
    next_handle: u32,
}

impl SkeletonAssets {
    pub fn new() -> Self {
        Self {
            skeletons: HashMap::new(),
            next_handle: 0,
        }
    }

    pub fn add(&mut self, skeleton: Skeleton) -> SkeletonHandle {
        let handle = SkeletonHandle(self.next_handle);
        self.next_handle += 1;
        self.skeletons.insert(handle, skeleton);
        handle
    }

    pub fn get(&self, handle: SkeletonHandle) -> Option<&Skeleton> {
        self.skeletons.get(&handle)
    }
}

impl Default for SkeletonAssets {
    fn default() -> Self {
        Self::new()
    }
}

/// Global storage for animation clip assets
#[derive(Clone)]
pub struct AnimationClipAssets {
    clips: HashMap<AnimationClipHandle, AnimationClip>,
    next_handle: u32,
}

impl AnimationClipAssets {
    pub fn new() -> Self {
        Self {
            clips: HashMap::new(),
            next_handle: 0,
        }
    }

    pub fn add(&mut self, clip: AnimationClip) -> AnimationClipHandle {
        let handle = AnimationClipHandle(self.next_handle);
        self.next_handle += 1;
        self.clips.insert(handle, clip);
        handle
    }

    pub fn get(&self, handle: AnimationClipHandle) -> Option<&AnimationClip> {
        self.clips.get(&handle)
    }
}

impl Default for AnimationClipAssets {
    fn default() -> Self {
        Self::new()
    }
}
