using KF3.Containers;
using System;
using UnityEngine;

public class KF3ObjectContainer : ObjectContainer
{
    protected override System.Type _serializeType => typeof(KF3ObjectContainerSerializable);

    public KF3CharacterContainer AsCharacter => this as KF3CharacterContainer;

    protected static KF3ModelViewerMain Main => KF3ModelViewerMain.Instance;

    protected override void Start()
    {
        if (DoNotSave) return;

        if(Frames.Count == 0)
        {
            SetKeyframe();
        }

        KF3ModelViewerMain.RegisterObject(this);
        var selector = UITimelineObjectEntry.Create(this);
        InstantiatedObjects.Add(selector.gameObject);

        KF3ModelViewerMain.Instance.SelectObject(this);
    }

    protected override void OnDestroy()
    {
        if (Main.SelectedObject == this)
        {
            Main.SelectObject(null);
        }

        KF3ModelViewerMain.UnregisterObject(this);

        base.OnDestroy();
    }

    #region Timeline
    public override DataType GetDataType()
    {
        switch (this)
        {
            case KF3FriendContainer _:
                return DataType.Character;
            case KF3CeruleanContainer _:
                return DataType.Character;
            case KF3StaticContainer _:
                return DataType.Object;
            default:
                Error.Log(Color.red, GetType().FullName);
                throw new NotImplementedException();
        }
    }
    #endregion
}
