using Godot;

namespace Cirno.Scripts.Components.FSM.Player;

public partial class Drowning : PlayerStateBase
{
    public override PlayerState StateId => PlayerState.Drowning;
    
    [Export]
    private PlayerAnimationProvider _animationProvider;
    
    public override void EnterState()
    {
        _animationProvider.PlayDrowningAnimation();
        
        // Wait for animation to be over and switch to death
        _animationProvider.OnAnimationEnded += AnimationProviderOnOnAnimationEnded;
    }

    private void AnimationProviderOnOnAnimationEnded(StringName animationName)
    {
        if (animationName != _animationProvider.DrowningAnimationName) return;
        
        _animationProvider.OnAnimationEnded -= AnimationProviderOnOnAnimationEnded;
        
        StateMachine.SetState(PlayerState.Dead);
        
    }
}