using FL.Battle;
using Spine.Unity;
using System;
using TMPro;
using UnityEngine;
using XGame.Framework.Map;
using XGame.Framework.ObjectCollection;
using XGame.Framework.Time;

namespace FL.Map
{
    public class MonsterEntityView : BattleEntityView<MonsterEntityVM>, IAttackContext, ISkillContext, ISpineContext
    {
        public void FindTarget(int skillId)
        {
            EventSingle.Instance.Notify(EventDefine.GameMainMapFindTarget, new FindTargetArgs()
            {
                entityId = Entity.EntityId,
                entityType = EEntityType.Player,
                range = Entity.Attr.AtkRange,
                skillId = skillId,
            });
        }

        #region IAttackContext
        Transform IAttackContext.ActionRoot => VM.ActionRoot;
        ITimeModule IAttackContext.Time => Context.Time;
        SpineComponent IAttackContext.Spine => GetComponent<SpineComponent>();
        bool IAttackContext.IsPartnerAtk => false;
        #endregion
        #region ISkillContext
        ITimeModule ISkillContext.Time => Context.Time;
        #endregion
        #region ISpineContext
        SkeletonAnimation ISpineContext.Skeleton => VM.Skeleton;
        ITimeModule ISpineContext.Time => Context.Time;
        #endregion

        protected override void OnEnable(object intent)
        {
        }
        protected override void OnDisable()
        {
            base.OnDisable();
        }
        protected override void OnStateChanged()
        {
            VM.StateText.text = Entity.State.ToString();
        }

    }
    public class MonsterEntityVM : EntityViewModel
    {
        public TextMeshPro StateText { get; private set; }
        public Transform ActionRoot { get; private set; }
        public SkeletonAnimation Skeleton { get; private set; }
        protected override void OnInit(IObjectCollector collector)
        {
            StateText = collector.GetComponent<TextMeshPro>("StateText");
            ActionRoot = collector.GetGameObject("ActionRoot").transform;
            Skeleton = collector.GetComponent<SkeletonAnimation>("Skeleton");
        }
    }
}