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.OrderStates
{
	public class OrderStateFacade : IOrderStateFacadeContract
	{
		private readonly IOrderStateRepository orderStateRepository;

		public OrderStateFacade(IOrderStateRepository orderStateRepository)
		{
			this.orderStateRepository = orderStateRepository;
		}

		public async Task<List<OrderStateVM>> GetAllOrderStatesAsync()
		{
			List<OrderState> orderStates = await orderStateRepository.GetAllAndDeletedAsync();

			if (orderStates is not null && orderStates.Count > 0)
			{
				return orderStates.Where(i => i.ID != Math.Abs(Convert.ToInt64(OrderState.Entry.ShoppingCart)))
					.Select(i => new OrderStateVM
				{
					ID = i.ID,
					Name = i.Name
				}).ToList();
			}

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