using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Music.Presentation;
using StructureMap;
using Music.Model;
using Music.Presentation.Playlist;
using Music.Presentation.Navigation;
using Web.Views.Shared;

namespace Web.Views.Song
{
    public partial class SongDetail : System.Web.UI.Page, ISongDetailView
    {
        private ISongDetailPresenter _presenter;

        protected void Page_Init(object sender, EventArgs e)
        {
            _presenter = new SongDetailPresenter(this,
                ObjectFactory.GetInstance<SongService>(),
                ObjectFactory.GetInstance<IPlaylist>(),
                ObjectFactory.GetInstance<IPageNavigator>());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter.Display();
        }

        #region ISongDetailView Members

        public int SongId
        {
            get
            {
                return int.Parse(Request.QueryString["SongId"]);
            }
        }

        public string SongTitle
        {
            set
            {
                this.litName.Text = value;
            }
        }

        public string ArtistName
        {
            set
            {
                this.litArtist.Text = value;
            }
        }

        public string AlbumName
        {
            set
            {
                this.litAlbum.Text = value;
            }
        }

        public IEnumerable<Album> AlbumList
        {
            set
            {
                // TODO: Update master page and add support for albums
            }
        }

        public IEnumerable<Artist> ArtistList
        {
            set
            {
                MusicStore musicMasterPage = (MusicStore)Page.Master;
                musicMasterPage.ArtistListControl.SetArtistsToDisplay(value);
            }
        }


        public string Genre
        {
            set
            {
                this.litGenre.Text = value;
            }
        }

        public string Track
        {
            set
            {
                this.litTrack.Text = value;
            }
        }
        #endregion

        protected void btnAddToPlaylist_Click(object sender, EventArgs e)
        {
            _presenter.AddSongToPlaylistAndShowPlaylistPage();
        }

    }
}