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;
using DiplomovaPrace.Model.Orders;

namespace DiplomovaPrace.Facades.PaymentStates
{
	public class PaymentStateFacade : IPaymentStateFacadeContract
	{
		private readonly IPaymentStateRepository paymentStateRepository;

		public PaymentStateFacade(IPaymentStateRepository paymentStateRepository)
		{
			this.paymentStateRepository = paymentStateRepository;
		}

		public async Task<List<PaymentStateVM>> GetAllPaymentStatesAsync()
		{
			List<PaymentState> paymentStates = await paymentStateRepository.GetAllAndDeletedAsync();

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

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