using InABox.Core;

namespace InABox.Database
{
    public class ScriptStore : Store<Script>
    {
        private static void CheckScriptCache(ScriptType type)
        {
            if (
                type == ScriptType.BeforeQuery
                || type == ScriptType.AfterQuery
                || type == ScriptType.AfterLoad
                || type == ScriptType.BeforeSave
                || type == ScriptType.AfterSave
                || type == ScriptType.BeforeDelete
                || type == ScriptType.AfterDelete
            )
                DbFactory.LoadScripts();
        }

        protected override void AfterSave(Script entity)
        {
            base.AfterSave(entity);
            CheckScriptCache(entity.ScriptType);
        }

        protected override void AfterDelete(Script entity)
        {
            base.AfterDelete(entity);
            CheckScriptCache(entity.ScriptType);
        }
    }
}