using System.Collections.Generic;
using System.Linq;
using System.Xml;
using MusicMetaTagger.Client.AllMusicGuide.Properties;
using MusicMetaTagger.Core.Model;

namespace MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Parser
{
	public class ArtistResultPageParser : ParserBase<List<ArtistResult>>
	{
		public override List<ArtistResult> Parse(XmlDocument xml)
		{
			var artistResults = new List<ArtistResult>();
			var settings = ArtistResultPageScraper.Default;
			var artistResultParser = new ArtistResultParser();

			if (XpathMatch(xml, settings.ArtistXpath))
			{
				var artistResultsXmlList = XpathMatchXmlList(xml, settings.ArtistXpath);
				artistResults = artistResultsXmlList.Select(artistResultParser.Parse).ToList();
				var i = 1;
				artistResults.ForEach(ar => ar.ResultOrder = i++);
			}
			return artistResults;
		}
	}
}