using System;
using System.Collections.Generic;
using System.Linq;
using DiplomovaPrace.Model.Orders;
using Havit.Extensions.DependencyInjection.Abstractions;

namespace DiplomovaPrace.Services.Orders
{
	[Service]
	public class AdminOrderPriceCalculator : IAdminOrderPriceCalculator
	{
		public decimal CalculateTotalOrderPrice(List<OrderItem> orderItems, DeliveryType deliveryType, PaymentType paymentType)
		{
			decimal totalOrderItemsPrice = orderItems.Sum(i => i.Price * i.Amount);

			if (deliveryType.ID == (int)DeliveryType.Entry.Delivery)
			{
				totalOrderItemsPrice += totalOrderItemsPrice >= 1000 ? 0 : deliveryType.Fee;
			}
			else
			{
				totalOrderItemsPrice += deliveryType.Fee;
			}

			totalOrderItemsPrice += paymentType.Fee;

			return totalOrderItemsPrice;
		}
	}
}
