using System.Collections.Generic;

namespace ChillConnect
{
    public sealed class ManagerOfManager : Singleton<ManagerOfManager>
    {
        private List<InterfaceManager> allManager = new();

        public void Init()
        {
            foreach (var manager in allManager)
            {
                manager.Init();
            }

            foreach (var manager in allManager)
            {
                manager.StartUp();
            }
        }

        public void AddManager(InterfaceManager interfaceManager)
        {
            if (!allManager.Contains(interfaceManager))
            {
                allManager.Add(interfaceManager);
            }
        }

        public void DisposeAllManager()
        {
            foreach (var manager in allManager)
            {
                manager.DisposeBefore();
            }

            foreach (var manager in allManager)
            {
                manager.Dispose();
            }

            GeneralKit.Destroy(AppObjConst.MonoManagerGo);
            allManager.Clear();
        }

        public override void Dispose()
        {
            base.Dispose();
            allManager.Clear();
            allManager = null;
        }
    }
}