using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace eSuite.WorkBench.WpfHelper
{
    /// <summary>
    /// Inherit from this base class to have the Interfaces used for WPF implemented.  This will allow you to save time when implementation properties on your view model.
    /// Just call OnPropertyChanging before changing the value of your property, then call OnPropertyChanged after the value has been changed.
    /// </summary>
    public class ViewModelBase : INotifyPropertyChanging, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public event PropertyChangingEventHandler PropertyChanging;

        /// <summary>
        /// Call this immediately after changing the value of your property
        /// </summary>
        /// <param name="propertyName">Please leave this blank it will be auto populated</param>
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Call this immediately before changing the value of your property
        /// </summary>
        /// <param name="propertyName">Please leave this blank it will be auto populated</param>
        protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }
    }
}
