namespace MyOffice.Web.Models.Account
{
	using System.ComponentModel.DataAnnotations;
	using Core.Extensions;
	using Data.Models.Accounts;
	using User;

	public class AccountViewModel
	{
		public string? Id { get; set; }

		[Required] 
		public string Name { get; set; } = null!;

		[Required] 
		public string CurrencyId { get; set; } = null!;
		public string? CurrencyName { get; set; }

		public List<MotionCategoryViewModel>? Categories { get; set; }

		[Required]
		public string CategoryId { get; set; } = null!;

		public List<AccessRightsViewModel>? AccessRights { get; set; }
	}

	public static class AccountViewModelExtensions
	{
		public static AccountViewModel ToModel(this Account input)
		{
			return new AccountViewModel
			{
				Id = input.Id.ToShort(),
				Name = input.Name,
				CurrencyId = input.CurrencyGlobalId,
				CurrencyName = input.CurrencyGlobal!.Name,
				Categories = input.Categories!
					.Select(x => x.Category!.ToModel())
					.ToList(),
				AccessRights = input.AccessRights!
					.Select(x => x.ToModel())
					.ToList(),
			};
		}
	}
}
