using System;
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.PaymentTypes
{
	public class PaymentTypeFacade : IPaymentTypeFacadeContract
	{
		private readonly IPaymentTypeRepository paymentTypeRepository;

		public PaymentTypeFacade(IPaymentTypeRepository paymentTypeRepository)
		{
			this.paymentTypeRepository = paymentTypeRepository;
		}

		public async Task<List<PaymentTypeVM>> GetAllPaymentTypesAsync()
		{
			List<Model.Orders.PaymentType> paymentTypes = await paymentTypeRepository.GetAllAndDeletedAsync();

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

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