using System;
using Intrepid.Core.Entities.Messages;
using Intrepid.Structures;
using Intrepid.Utilities;
using UnityEngine;

namespace Intrepid.Gameplay.Entities.Player.Sentinel.StateMachine.States
{
    public class SentinelStateFall : SentinelState
    {
        [GroupConfigurations, SerializeField] private AnimationClip fall;
        
        public override SentinelStateType GetStateKey()
        {
            return SentinelStateType.Fall;
        }

        protected override void Subscriptions()
        {
            Subscribe<EntityRecoverStableGroundEvent>(e =>
            {
                if (!string.Equals(Brain.Entity.Id, e.EntityId, StringComparison.Ordinal)) return;
                Brain.ChangeState(SentinelStateType.FallLanding);
            });
        }
        
        protected override void RunOnEnter(ParameterStore ps)
        {
            EndCadence();
            Brain.Controls.ResetDash();
            Brain.Entity.ModelAnimation.CrossFade(fall, .1f);
            Brain.Entity.DesiredVelocity = Vector2.zero;
        }

        protected override void RunOnExit()
        {
        }

        public override void RunOnUpdate()
        {
        }
    }
}