using System.Collections.Generic;
using System.Globalization;
using MileageTraker.Web.ViewModels.ServiceReminder;

namespace MileageTraker.Web.ViewModels.VehicleService
{
	public class VehicleServiceResultsViewModel
	{
		public IEnumerable<VehicleServiceViewModel> ServiceItems { get; set; }
		public IList<ServiceReminderViewModel> UpcomingServiceReminders { get; set; }
		public Dictionary<string, List<string>> AvailableYearMonths { get; set; }
		public IEnumerable<string> SelectedYearMonths
		{
			get
			{
				if (!string.IsNullOrEmpty(Year))
					return AvailableYearMonths[Year];
				return new List<string>();
			}
		}

		// filter parameters
		public string Year { get; set; }
		public string Month { get; set; }
		public string MonthRange { get; set; }
		public string VehicleId { get; set; }

		public VehicleServiceResultsViewModel(
			IEnumerable<VehicleServiceViewModel> serviceItems,
			IList<ServiceReminderViewModel> upcomingServiceReminders,
			VehicleServiceQueryViewModel query, 
			Dictionary<string, List<string>> availableYearMonths)
		{
			ServiceItems = serviceItems;
			UpcomingServiceReminders = upcomingServiceReminders;
			AvailableYearMonths = availableYearMonths;
			Year = query.Year.HasValue ? query.Year.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
			Month = query.Month.HasValue ? query.Month.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
			MonthRange = query.MonthRange.HasValue ? query.MonthRange.Value.ToString(CultureInfo.InvariantCulture) : string.Empty;
			VehicleId = query.VehicleId;
		}
	}
}
