using System.Collections.Generic;
using UnityEngine;

namespace Assets.Source.Patterns.ObjectPool
{
    public class ObjectPoolTest : MonoBehaviour
    {
        public GameObject Prefab;
        public List<GameObject> ToRelease;

        void OnGUI()
        {
            GUI.BeginGroup(new Rect(10, 10, 400, 400));

            if (GUILayout.Button("Warm"))
            {
                var prefabPoolable = Prefab.GetComponent<IPoolObject>();
                PoolManager.Instance.Warm(prefabPoolable);
            }
            if (GUILayout.Button("Spawn"))
            {
                var prefabPoolable = Prefab.GetComponent<IPoolObject>();
                var clone = PoolManager.Instance.Spawn(prefabPoolable);
            }
            if (GUILayout.Button("Release"))
            {
                foreach (var o in ToRelease)
                {
                    var releasePoolable = o.GetComponent<IPoolObject>();
                    PoolManager.Instance.Release(releasePoolable);
                }
            }

            GUI.EndGroup();
        }
    }
}
