using System;

[System.Serializable]
public class KeyframeData
{
    public SerializableTransform Root;

    public KeyframeData() { }

    public KeyframeData(ObjectContainer container)
    {
        this.Root = new SerializableTransform(container.transform);
    }

    public virtual KeyframeData Clone()
    {
        var keyframe = new KeyframeData();
        keyframe.Root = new SerializableTransform(this.Root);
        return keyframe;
    }

    public virtual KeyframeData Lerp(KeyframeData target, float amount)
    {
        var copy = this.Clone();
        copy.Root = copy.Root.LerpWith(target.Root, amount);
        return copy;
    }

    /// <summary>
    /// Call type's constructor with container as parameter
    /// </summary>
    /// <param name="type">Must derive from KeyframeData</param>
    /// <param name="container">Type must accept it as the only constructor parameter</param>
    /// <returns></returns>
    public static KeyframeData Serialize(Type type, ObjectContainer container)
    {
        return Activator.CreateInstance(type, new object[] { container }) as KeyframeData;
    }
}