using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using AutoMapper;

namespace MileageTraker.Web.ViewModels.FuelLog
{
	public class FuelLogIndexViewModel
	{
		[HiddenInput(DisplayValue = false)]
		public int FuelLogId { get; set; }

		[DataType(DataType.Date)]
		[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
		public DateTime Date { get; set; }

		[StringLength(128)]
		[Display(Name = "Driver Name")]
		public string DriverFullName { get; set; }

		[Display(Name = "Tag#")]
		public string TagNumber { get; set; }

		public int Odometer { get; set; }

		[Display(Name = "MPG")]
		public double MPG { get; set; }

		[Display(Name = "Gas Purchased")]
		public double GasPurchased { get; set; }

		[Display(Name = "Total Price")]
		public decimal TotalPrice { get; set; }

		// Matched log
		[HiddenInput(DisplayValue = false)]
		public int? LogId { get; set; }
		
		static FuelLogIndexViewModel()
		{
			Mapper.CreateMap<Models.FuelLog, FuelLogIndexViewModel>()
				.ForMember(dest => dest.LogId,
			               opt => opt.ResolveUsing(
							   fl => fl.Log != null ? (int?)fl.Log.LogId : null
							   ));
		}

		public FuelLogIndexViewModel(Models.FuelLog fuelLog)
		{
			Mapper.Map(fuelLog, this);
		}
	}
}