using Microsoft.Xna.Framework.Input;
using MonoGame.FourEngine.Attributes;
using System;
using System.Collections.Generic;

namespace MonoGame.FourEngine.Services
{
    [Service]
    public interface IKeyboardControl
    {
        void Update(TimeSpan deltaTime);
        IReadOnlyDictionary<Keys, KeyState> State { get; }
    }

    public class KeyState
    {
        public bool IsPressed { get; set; }
        public bool WasPressed { get; set; }
        public CancelableEventArgs ClickCancellable { get; internal set; }

        public bool HasClicked => !ClickCancellable.IsCanceled
            && IsPressed && !WasPressed;

        public KeyState()
        {
            ClickCancellable = new CancelableEventArgs(this, false);
        }
    }
}