using System.Collections.ObjectModel;
using System.ComponentModel;
using System;
namespace TrailerPlayer
{
    public class ViewModel : INotifyPropertyChanged
    {
        ObservableCollection<Movie> trailers;
        Model model;
        public ViewModel()
        {
            model = new Model();
            model.MovieSearchCompleted += new MovieSearchCompletedEventHandler(model_MovieSearchCompleted);
        }
        public ObservableCollection<Movie> Trailers
        {
            get { return trailers; }
            private set
            {
                trailers = value;
                RaisePropertyChanged("Trailers");
            }
        }
        public void SearchVideos(string key)
        {
            model.SearchVideos(key);
            
        }
        public event EventHandler SearchCompleted;
        void model_MovieSearchCompleted(object sender, MovieSearchCompletedEventArgs e)
        {
            Trailers = e.Trailers;
            if (SearchCompleted != null)
                SearchCompleted(this, null);
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
        #endregion
    }
}
