namespace MyOffice.Web.Models.Currency
{
	using Core.Extensions;
	using Data.Models.Currencies;
	using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;

	public class CurrencyViewModel
	{
		public string Id { get; set; } = null!;
		public string Code { get; set; } = null!;
		public string Name { get; set; } = null!;
		public decimal? Rate { get; set; }
		public int? Quantity { get; set; }
		public DateTime? RateDate { get; set; }
	}

	public static class CurrencyViewModelExtensions
	{
		public static CurrencyViewModel ToModel(this Currency input, CurrencyRate? rate = null)
		{
			return new CurrencyViewModel
			{
				Id = input.Id.ToShort(),
				Code = input.CurrencyGlobal!.Id,
				Name = input.Name,
				Quantity = rate?.Quantity,
				Rate = rate?.Rate,
				RateDate = rate?.DateTime,
			};
		}
	}
}
