using System;
using System.Collections.Generic;
using MusicMetaTagger.Core.Model;
using MusicMetaTagger.Core.Services;
using MusicMetaTagger.Core.Utility;

namespace MusicMetaTagger.Client.AllMusicGuide.Services
{
	public class MusicGuideCache : IMusicGuide
	{
		private readonly Func<string, Album> _getAlbum;
		private readonly Func<string, Artist> _getArtist;
		private readonly Func<string, Song> _getSong;
		private readonly Func<string, List<ArtistResult>> _searchArtist;
		private readonly Func<string, List<AlbumResult>> _searchAlbum;
		private readonly Func<string, List<SongResult>> _searchSong;

		public MusicGuideCache(IMusicGuide @base)
		{
			Func<string, Album> getAlbum = @base.GetAlbum;
			_getAlbum = getAlbum.MemoizeFunction();

			Func<string, Artist> getArtist = @base.GetArtist;
			_getArtist = getArtist.MemoizeFunction();

			Func<string, Song> getSong = @base.GetSong;
			_getSong = getSong.MemoizeFunction();

			Func<string, List<ArtistResult>> searchArtist = @base.SearchArtist;
			_searchArtist = searchArtist.MemoizeFunction();

			Func<string, List<AlbumResult>> searchAlbum = @base.SearchAlbum;
			_searchAlbum = searchAlbum.MemoizeFunction();

			Func<string, List<SongResult>> searchSong = @base.SearchSong;
			_searchSong = searchSong.MemoizeFunction();
		}

		public Artist GetArtist(string artistId)
		{
			return _getArtist(artistId);
		}

		public Album GetAlbum(string albumId)
		{
			return _getAlbum(albumId);
		}

		public Song GetSong(string songId)
		{
			return _getSong(songId);
		}

		public List<ArtistResult> SearchArtist(string artistName)
		{
			return _searchArtist(artistName);
		}

		public List<AlbumResult> SearchAlbum(string albumName)
		{
			return _searchAlbum(albumName);
		}

		public List<SongResult> SearchSong(string songName)
		{
			return _searchSong(songName);
		}
	}
}