using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DiplomovaPrace.Contracts.Orders;
using DiplomovaPrace.Contracts.Orders.ViewModels;
using DiplomovaPrace.DataLayer.Repositories.Orders;

namespace DiplomovaPrace.Facades.DeliveryTypes
{
	public class DeliveryTypeFacade : IDeliveryTypeFacadeContract
	{
		private readonly IDeliveryTypeRepository deliveryTypeRepository;

		public DeliveryTypeFacade(IDeliveryTypeRepository deliveryTypeRepository)
		{
			this.deliveryTypeRepository = deliveryTypeRepository;
		}

		public async Task<List<DeliveryTypeVM>> GetAllDeliveryTypesAsync()
		{
			List<Model.Orders.DeliveryType> deliveryTypes = await deliveryTypeRepository.GetAllAndDeletedAsync();

			if (deliveryTypes is not null && deliveryTypes.Count > 0)
			{
				return deliveryTypes.Select(i => new DeliveryTypeVM
				{
					ID = i.ID,
					Name = i.Name,
					Fee = i.Fee
				}).ToList();
			}

			return new List<DeliveryTypeVM>();
		}
	}
}
