using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DiplomovaPrace.Model.Orders;
using Microsoft.EntityFrameworkCore;

namespace DiplomovaPrace.DataLayer.Repositories.Orders
{
	public partial class OrderDbRepository : IOrderRepository
	{
		public async Task<List<Order>> GetAllByAddressIDAsync(int id)
		{
			return await Data.Where(i => i.DeliveryAddressID == id || i.InvoicingAddressID == id).ToListAsync().ConfigureAwait(false);
		}

		public async Task<List<Order>> GetAllByUserID(int id)
		{
			return await Data.Where(i => i.LoginAccountID == id && i.OrderStateID != Math.Abs((int)OrderState.Entry.ShoppingCart)).ToListAsync();
		}

		public async Task<Order> GetOrderInCartByCustomerIDAsync(int id)
		{
			return await Data.FirstOrDefaultAsync(i => i.LoginAccountID == id && i.OrderStateID == Math.Abs((int)OrderState.Entry.ShoppingCart)).ConfigureAwait(false);
		}
	}
}