using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Platnosci.Core.Interface;
using Platnosci.Core.Linq;

namespace Platnosci.Tests.Web
{
    public class FakeDataContext : IDataContext
    {
        private List<PlatnosciEcard> listaPayment = new List<PlatnosciEcard>();
       
        private string code_Ok = "payment_deposited";        //transakcja potwierdzona do rozliczenia
       
        private readonly List<object> lista = new List<object>();
        private Function _f = new Function();
 

        public IQueryable<T> GetTable<T>() where T : class
        {
            var query = lista.Where(objects => typeof(T).IsAssignableFrom(objects.GetType()));
            return query.Select(o => (T)o).AsQueryable();
        }

        public void Insert<T>(T item) where T : class
        {
            lista.Add(item);
        }

        public void Delete<T>(T item) where T : class
        {
            lista.Remove(item);
        }

        public void SubmitChanges()
        {
            InvokeCompleted(EventArgs.Empty);
        }

        public event EventHandler Completed;

        private void InvokeCompleted(EventArgs e)
        {
            var completedHandler = Completed;
            if (completedHandler != null) completedHandler(this, e);
        }

        public void Dispose()
        {
        }
        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
        {
            throw new NotImplementedException();
        }
        public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
        {
            
            PlatnosciEcard platnosc = _f.createNewPayment(123456, true, DateTime.Now, 123);
            List<PlatnosciEcard> payment = new List<PlatnosciEcard>();
            List<PotwierdzeniaEcard> listaConfirm = new List<PotwierdzeniaEcard>();
            listaConfirm.Add((PotwierdzeniaEcard)lista[0]);
            payment.Add(platnosc);

            List<PotwierdzeniaEcard> new_confirm = new List<PotwierdzeniaEcard>();

            if (platnosc.IDFaktury == idFaktury) 
            {
                if (listaConfirm[0].ORDERNUMBER == platnosc.ORDERNUMBER && listaConfirm[0].CURRENTSTATE == code_Ok)
                    new_confirm.Add(listaConfirm[0]);
            }
            System.Diagnostics.Debug.WriteLine("lista" + new_confirm.Count());  
            return new_confirm;
        }
    }
}
