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

namespace TFramework
{
    public abstract class BindDataBase<T>
    {
        protected List<UIBehaviour> m_UIs;

        private T _data;

        public T Data
        {
            get => _data;
            set
            {
                _data = value;
                DataValueChangeEvent();
            }
        }

        /// <summary>
        /// 数据改变事件
        /// </summary>
        protected abstract void DataValueChangeEvent();

        /// <summary>
        /// 绑定UI
        /// </summary>
        /// <param name="uI"></param>
        public virtual void Bind(UIBehaviour uI)
        {
            m_UIs.Add(uI);
            BindEvent(uI);
        }

        protected abstract void BindEvent(UIBehaviour uI);

        protected virtual void Bind(IEnumerable<UIBehaviour> uIs)
        {
            foreach (var item in uIs)
                Bind(item);
        }

        public BindDataBase()
        {
            m_UIs = new List<UIBehaviour>();
        }

        public BindDataBase(UIBehaviour uI)
        {
            m_UIs = new List<UIBehaviour>();
            Bind(uI);
        }

        public BindDataBase(IEnumerable<UIBehaviour> uIs)
        {
            m_UIs = new List<UIBehaviour>();
            Bind(uIs);
        }
    }
}

