using XGame.Database;
using XGame.Framework.Asyncs;
using XGame.Framework.Loadable;
using XGame.Framework.Nodes;

namespace FL.Nodes.GameMain
{
    public class TableComponent : NodeComponent, ILoadAsyncHandle
    {
        public override void OnDisable()
        {
            Context.Tree.Remove(NodeKeys.Partners);
            Context.Tree.Remove(NodeKeys.DragonEgg);
        }

        public override void OnEnable(object intent)
        {
            Context.Tree.AddAsync(NodeKeys.Partners);
            Context.Tree.AddAsync(NodeKeys.DragonEgg);
        }

        void ILoadAsyncHandle.OnLoadAsync(IAsyncGroup group)
        {
            ChapterTableRepo.LoadAsync().Join(group);
            MapTableRepo.LoadAsync().Join(group);
            MonsterTableRepo.LoadAsync().Join(group);
            PartnerTableRepo.LoadAsync().Join(group);
            SkillTableRepo.LoadAsync().Join(group);
            SkillVfxsTableRepo.LoadAsync().Join(group);
            BuffTableRepo.LoadAsync().Join(group);
            EnergyTableRepo.LoadAsync().Join(group);
            EquipmentTableRepo.LoadAsync().Join(group);
            EquipmentBaseAttrTableRepo.LoadAsync().Join(group);
            EquipmentDisassemblyTableRepo.LoadAsync().Join(group);
            EquipmentDropTableRepo.LoadAsync().Join(group);
            EquipmentPeculiarAttrTableRepo.LoadAsync().Join(group);
            LevelTableRepo.LoadAsync().Join(group);
            AttrDescTableRepo.LoadAsync().Join(group);
            ItemTableRepo.LoadAsync().Join(group);
            EpigraphTableRepo.LoadAsync().Join(group);
        }

        void ILoadAsyncHandle.OnUnloadAsync(IAsyncGroup group)
        {
            ChapterTableRepo.Unload();
            MapTableRepo.Unload();
            MonsterTableRepo.Unload();
            PartnerTableRepo.Unload();
            SkillTableRepo.Unload();
            SkillVfxsTableRepo.Unload();
            BuffTableRepo.Unload();
            EnergyTableRepo.Unload();
            EquipmentTableRepo.Unload();
            EquipmentBaseAttrTableRepo.Unload();
            EquipmentDisassemblyTableRepo.Unload();
            EquipmentDropTableRepo.Unload();
            EquipmentPeculiarAttrTableRepo.Unload();
            LevelTableRepo.Unload();
            EpigraphTableRepo.Unload();
        }
    }
}
