using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TrailerPlayer.MovieSearchServiceReference;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace TrailerPlayer
{
    public class Movie
    {
        private string _Title;
        private string _Source;
        private string _Picture;
        private string _Thumb;
        private string _Description;
        private string _Type;
        private string _Director;
        private string _Cast;
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        public string Source
        {
            get { return _Source; }
            set { _Source = value; }
        }

        public string Picture
        {
            get { return _Picture; }
            set { _Picture = value; }
        }

        public string Thumb
        {
            get { return _Thumb; }
            set { _Thumb = value; }
        }

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        public string Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        public string Director
        {
            get { return _Director; }
            set { _Director = value; }
        }

        public string Cast
        {
            get { return _Cast; }
            set { _Cast = value; }
        }

        public Movie()
        {
        }
    }
    public delegate void MovieSearchCompletedEventHandler(object sender, MovieSearchCompletedEventArgs e);
    public class Model
    {
      
      public event MovieSearchCompletedEventHandler MovieSearchCompleted;
          MovieSearchServiceClient sc;
          public Model()
          {
              sc = new MovieSearchServiceClient();
              sc.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(sc_SearchCompleted);
          }
        public void SearchVideos(string key)
        {
            sc.SearchAsync(key);
        }

        void sc_SearchCompleted(object sender, SearchCompletedEventArgs e)
        {
            ObservableCollection<Movie> result= new ObservableCollection<Movie>();
            foreach (MovieSearchServiceReference.Movie movie in e.Result)
            {
                result.Add(new Movie
                {
                    Title = movie.Title,
                    Source = movie.Source,
                    Picture = movie.Picture,
                    Thumb=movie.Thumb,
                    Description = movie.Description,
                    Type = movie.Type,
                    Director = movie.Director,
                    Cast = movie.Cast
                }
                );
            }
            if(MovieSearchCompleted!=null)
                MovieSearchCompleted(this,new MovieSearchCompletedEventArgs(result));
        }
    }
    public class MovieSearchCompletedEventArgs : EventArgs
    {
        private ObservableCollection<Movie> _result;

        public ObservableCollection<Movie> Trailers
        {
            get { return _result; }
        }
        public MovieSearchCompletedEventArgs(ObservableCollection<Movie> result)
        {
            this._result = result;
        }
    }
}
