namespace ChillConnect
{
    public abstract class BaseModel
    {
        public string modelName;
        private string localStorageKey;

        protected ModuleManager mOduleManager;

        protected ModelDispatcher modelDispatcher;
        protected CtrlDispatcher ctrlDispatcher;
        protected UICtrlDispatcher uiCtrlDispatcher;
        protected DataDispatcher dataDispatcher;
        protected GameDispatcher gameDispatcher;

        public void New()
        {
            OnNew();
        }

        public void Init()
        {
            Assignment();
            AddListener();
            AddServerListener();
            OnInit();
        }

        public void StartUp()
        {
            OnStartUp();
        }

        public void GameStart()
        {
            OnGameStart();
        }

        public void Reset()
        {
            Dispose();
            Init();
        }

        public void Dispose()
        {
            RemoveListener();
            RemoveServerListener();
            OnDispose();
            UnAssignment();
        }

        protected virtual void Assignment()
        {
            mOduleManager = ModuleManager.Instance;

            modelDispatcher = ModelDispatcher.Instance;
            ctrlDispatcher = CtrlDispatcher.Instance;
            uiCtrlDispatcher = UICtrlDispatcher.Instance;
            dataDispatcher = DataDispatcher.Instance;
            gameDispatcher = GameDispatcher.Instance;
        }

        protected virtual void UnAssignment()
        {
            mOduleManager = null;

            modelDispatcher = null;
            ctrlDispatcher = null;
            uiCtrlDispatcher = null;
            dataDispatcher = null;
            gameDispatcher = null;
        }

        protected virtual void OnNew()
        {
        }

        protected abstract void OnInit();

        protected virtual void OnStartUp()
        {
        }

        protected virtual void OnGameStart()
        {
        }

        protected abstract void OnDispose();

        protected virtual void AddListener()
        {
        }

        protected virtual void RemoveListener()
        {
        }

        protected virtual void AddServerListener()
        {
        }

        protected virtual void RemoveServerListener()
        {
        }
    }
}