using System;
using System.ComponentModel;

namespace C1.Silverlight.FlexGridExcel
{
    /// <summary>
    /// Custom version of SortDescription that implements INotifyPropertyChanged
    /// so it can be used in binding scenarios.
    /// </summary>
    public class BindableSortDescription : INotifyPropertyChanged
    {
        // ** fields
        string _name;
        ListSortDirection _direction;

        // ** ctors

        /// <summary>
        /// Initializes a new instance of a <see cref="BindableSortDescription"/>.
        /// </summary>
        public BindableSortDescription()
        {
        }
        /// <summary>
        /// Initializes a new instance of a <see cref="BindableSortDescription"/>.
        /// </summary>
        /// <param name="propertyName">The name of the property to sort the list by.</param>
        /// <param name="direction">The sort order.</param>
        public BindableSortDescription(string propertyName, ListSortDirection direction)
        {
            _name = propertyName;
            _direction = direction;
        }

        // ** object model

        /// <summary>
        /// Gets or sets the name of the property to sort the list by.
        /// </summary>
        public string PropertyName
        {
            get { return _name; }
            set
            {
                _name = value;
                OnPropertyChanged("PropertyName");
            }
        }
        /// <summary>
        /// Gets or sets the sort direction.
        /// </summary>
        public ListSortDirection Direction
        {
            get { return _direction; }
            set
            {
                _direction = value;
                OnPropertyChanged("Direction");
            }
        }
        /// <summary>
        /// Raises the <see cref="PropertyChanged"/> event.
        /// </summary>
        /// <param name="propName">Name of the property whose value changed.</param>
        protected virtual void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
        /// <summary>
        /// Occurs when the value of a property changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
