using MusicMetaTagger.Core.Model;
using MusicMetaTagger.Core.Services;

namespace MusicMetaTagger.Client.AllMusicGuide.Services
{
	public class TrackOriginalRelease : ITrackOriginalRelease
	{
		private readonly IMusicGuide _musicGuide;

		public TrackOriginalRelease(IMusicGuide musicGuide)
		{
			_musicGuide = musicGuide;
		}

		public Track GetTrackOriginalRelease(Track track)
		{
			var song = _musicGuide.GetSong(track.TrackId);
			// TODO: iterate through albums until track is found
			var firstAlbum = song.AppearsOnAlbum[0];

			var album = _musicGuide.GetAlbum(firstAlbum.AlbumId);
			return TrackSimilarity.MatchTrack(track, album.Tracks);
		}
	}
}