using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[System.Serializable]
public class SceneContainer
{
    public string GUID;
    public List<ObjectContainer> AllObjects = new List<ObjectContainer>();

    public List<T> Objects<T>() where T : ObjectContainer
    {
        return AllObjects.Cast<T>().ToList();
    }

    public SceneContainer() { }

    public static SceneContainer Create<T>(ModelViewerMain main) where T : SceneContainer, new()
    {
        var container = new T();
        container.Init(main);
        return container;
    }

    public virtual void Init(ModelViewerMain main)
    {
        GUID = "scene";
        if (!AllObjects.Contains(main.MainCameraOrbit)) { AllObjects.Add(main.MainCameraOrbit); }
    }

    public virtual SceneSerializable Serialize()
    {
        return new SceneSerializable(this);
    }

    public virtual void Destroy()
    {
        for (int i = AllObjects.Count - 1; i >= 0; i--)
        {
            var obj = AllObjects[i];
            obj.Destroy();
        }

        AllObjects.Clear();
    }
}