namespace AdaptiveLayout.ViewModel
{
    using Model;
    using System.Collections.ObjectModel;
    using System.ComponentModel;

    public class MainViewModel : INotifyPropertyChanged
    {
        private ObservableCollection<Book> books;

        public ObservableCollection<Book> Books
        {
            get
            {
                return books;
            }

            set
            {
                if (books != value)
                {
                    books = value;
                    RaisePropertyChanged("Books");
                }
            }
        }

        private Book selectedItem;

        public Book SelectedItem
        {
            get
            {
                return selectedItem;
            }

            set
            {
                if (selectedItem != value)
                {
                    selectedItem = value;
                    RaisePropertyChanged("SelectedItem");
                }
            }
        }

        private BooksRepository repository;

        public MainViewModel()
        {
            repository = new BooksRepository();
            Books = repository.LoadBooksData();
        }

        #region INPC

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
