using System.Collections.Generic;
using Assets.Source.Core.Interfaces;
using UnityEngine;

namespace Assets.Source.Patterns.ScriptableObjects
{
    public abstract class RuntimeSet<T> : ScriptableObject, ISerializationCallbackReceiver, IScriptableWorker
    {
        public List<T> Items = new List<T>();

        public void Add(T item)
        {
            if (!Items.Contains(item))
                Items.Add(item);
        }

        public void Remove(T item)
        {
            if (Items.Contains(item))
                Items.Remove(item);
        }

        void OnEnable()
        {
            VOnEnable();
        }
        void OnDisable()
        {
            VOnDisable();
        }

        public void Update()
        {
            VUpdate();
        }

        public void FixedUpdate()
        {
            VFixedUpdate();
        }

        public void OnBeforeSerialize()
        {
            VOnBeforeSerialize();
        }

        public void OnAfterDeserialize()
        {
            Items = new List<T>();   
            VOnAfterDeserialize();
        }

        public void ClearContent()
        {
            VClearContent();
        }

        public void Init()
        {
            VInit();
        }

        protected virtual void VInit()
        {
        }

        protected virtual void VOnEnable()
        {
        }

        protected virtual void VOnDisable()
        {
        }

        protected virtual void VUpdate()
        {
        }

        protected virtual void VFixedUpdate()
        {
        }

        protected virtual void VOnBeforeSerialize()
        {
        }

        protected virtual void VOnAfterDeserialize()
        {
        }

        protected virtual void VClearContent()
        {
        }
    }
}
