using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using log4net;

using Crud;

namespace CrudLogging
{
    public class CrudLogging<TEntity> : ICrud<TEntity>
    {
        public CrudLogging(ICrud<TEntity> decoratedCrud, ILog log)
        {
            this.decoratedCrud = decoratedCrud;
            this.log = log;
        }

        public void Create(TEntity entity)
        {
            log.InfoFormat("Tworzenie wiersza typu {0}", typeof(TEntity).Name);
            decoratedCrud.Create(entity);
        }

        public TEntity ReadOne(Guid identity)
        {
            log.InfoFormat("Odczytanie wiersza typu {0} o identyfikatorze {1}", typeof(TEntity).Name, identity);
            return decoratedCrud.ReadOne(identity);
        }

        public IEnumerable<TEntity> ReadAll()
        {
            log.InfoFormat("Odczytanie wszystkich wierszy typu {0}", typeof(TEntity).Name);
            return decoratedCrud.ReadAll();
        }

        public void Update(TEntity entity)
        {
            log.InfoFormat("Zmiana wiersza typu {0}", typeof(TEntity).Name);
            decoratedCrud.Update(entity);
        }

        public void Delete(TEntity entity)
        {
            log.InfoFormat("Usunięcie wiersza typu {0}", typeof(TEntity).Name);
            decoratedCrud.Delete(entity);
        }

        private readonly ICrud<TEntity> decoratedCrud;
        private readonly ILog log;
    }
}