using System.Windows.Input;

namespace MauiTestApp.Command
{
    public class RelayCommand : ICommand
    {
        public event EventHandler? CanExecuteChanged;

        Action execute;
        Func<bool>? canExecute;

        public RelayCommand(Action action)
        {
            execute = action!;
        }

        public RelayCommand(Action action, Func<bool> canExecute)
        {
            execute = action!;
            this.canExecute = canExecute;
        }

        public bool CanExecute(object? parameter) => canExecute == null || canExecute();

        public void Execute(object? parameter) => execute();

        public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, new());
    }
}
