using Godot;
using System.Collections.Generic;
using System.Text;

namespace Rokojori
{  
  [GlobalClass,Tool, Icon("res://addons/rokojori_action_library/Icons/AudioManager.svg") ]
  public partial class AudioManager:Node
  {
    [Export]
    public AudioManagerData data;
    
    Dictionary<SelectorFlag,float> _lastPlayTime = new Dictionary<SelectorFlag, float>();

    public float GetLastPlayed( SelectorFlag selectorFlag )
    {
      if ( ! _lastPlayTime.ContainsKey( selectorFlag ) )
      {
        return -1;
      }

      return _lastPlayTime[ selectorFlag ];
    }

    public void RecordSoundPlaying( SelectorFlag selectorFlag )
    {
      _lastPlayTime[ selectorFlag ] = TimeLine.osTime;
    }

    public bool CanPlay( SelectorFlag selectorFlag, float blockDuration )
    {
      if ( ! _lastPlayTime.ContainsKey( selectorFlag ) )
      {
        return true;
      }

      return ( TimeLine.osTime - _lastPlayTime[ selectorFlag ] ) > blockDuration;

    }
  }
}