using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace MusicMetaTagger.Core.Model
{
	[Serializable]
	public class Album
	{
		/// <summary>
		///   Album AMG Id
		/// </summary>
		[Key]
		public string AlbumId { get; set; }

		/// <summary>
		///   Album title
		/// </summary>
		public string Title { get; set; }

		/// <summary>
		///   Artist name
		/// </summary>
		public string ArtistName { get; set; }

		/// <summary>
		///   Artist AMG Id
		/// </summary>
		public string ArtistId { get; set; }

		/// <summary>
		///   Album release date
		/// </summary>
		public string ReleaseDate { get; set; }

		/// <summary>
		///   Url to cover image
		/// </summary>
		public string CoverUrl { get; set; }

		/// <summary>
		///   Album review
		/// </summary>
		public string Review { get; set; }

		/// <summary>
		///   Album reviewer
		/// </summary>
		public string Reviewer { get; set; }

		/// <summary>
		///   Album rating (0, 1, ..., 10)
		/// </summary>
		public int? Rating { get; set; }

		/// <summary>
		///   Album pick
		/// </summary>
		public bool Pick { get; set; }

		/// <summary>
		///   Album Styles
		/// </summary>
		public List<string> Styles { get; set; }

		/// <summary>
		///   Album Moods
		/// </summary>
		public List<string> Moods { get; set; }

		/// <summary>
		///   Album Tracks
		/// </summary>
		public List<Track> Tracks { get; set; }

		/// <summary>
		///   Album Themes
		/// </summary>
		public List<string> Themes { get; set; }

		/// <summary>
		///   Indicates that this album is by various artists
		/// </summary>
		public bool VariousArtists { get; set; }

		/// <summary>
		///   Indicates that this album is a sound track
		/// </summary>
		public bool Soundtrack { get; set; }

		/// <summary>
		///   Returns the year the album was released
		/// </summary>
		/// <returns> </returns>
		/// <exception cref="ApplicationException">Thrown if release date is null or empty</exception>
		public int GetReleaseYear()
		{
			if (string.IsNullOrEmpty(ReleaseDate))
				throw new ApplicationException("Release Date is null");
			var match = new Regex(@"\d{4}").Match(ReleaseDate);
			return match.Captures.Count > 0
			       	? Convert.ToInt32(match.Captures[0].Value)
			       	: 0;
		}
	}
}