using System.Collections.Generic;
using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Scraper;
using MusicMetaTagger.Core.Model;
using MusicMetaTagger.Core.Services;

namespace MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess
{
	/// <summary>
	///   Inspired by this Perl module: http://backpan.perl.org/authors/id/Y/YO/YOHAMED/WWW-AllMusicGuide.html
	/// </summary>
	public class MusicGuideScraper : IMusicGuide
	{
		private readonly IScraper<Album> _albumScraper;
		private readonly IScraper<List<AlbumResult>> _albumResultScraper;
		private readonly IScraper<Artist> _artistScraper;
		private readonly IScraper<List<ArtistResult>> _artistResultScraper;
		private readonly IScraper<List<ArtistDiscography>> _discographyScraper;

		private readonly IScraper<List<SongResult>> _songResultScraper;
		private readonly IScraper<Song> _songScraper;

		public MusicGuideScraper(IScraper<Album> albumScraper, IScraper<List<AlbumResult>> albumResultScraper, IScraper<Artist> artistScraper, IScraper<List<ArtistResult>> artistResultScraper, IScraper<List<ArtistDiscography>> discographyScraper, IScraper<List<SongResult>> songResultScraper, IScraper<Song> songScraper)
		{
			_albumScraper = albumScraper;
			_albumResultScraper = albumResultScraper;
			_artistScraper = artistScraper;
			_artistResultScraper = artistResultScraper;
			_discographyScraper = discographyScraper;
			_songResultScraper = songResultScraper;
			_songScraper = songScraper;
		}

		public Artist GetArtist(string artistId)
		{
			var artist = _artistScraper.Scrape(artistId);
			artist.Discography = _discographyScraper.Scrape(artistId);
			return artist;
		}

		public Album GetAlbum(string albumId)
		{
			return _albumScraper.Scrape(albumId);
		}

		public Song GetSong(string songId)
		{
			return _songScraper.Scrape(songId);
		}

		public List<ArtistResult> SearchArtist(string artistName)
		{
			return _artistResultScraper.Scrape(artistName);
		}

		public List<AlbumResult> SearchAlbum(string albumName)
		{
			return _albumResultScraper.Scrape(albumName);
		}

		public List<SongResult> SearchSong(string songName)
		{
			return _songResultScraper.Scrape(songName);
		}
	}
}