using JamesKovacs.IoCArticle.IoCContainer.Domain;

namespace JamesKovacs.IoCArticle.IoCContainer.Repositories {
    public class AuditingInvoiceRepository : IInvoiceRepository {
        private readonly IInvoiceRepository invoiceRepository;
        private readonly IAuditWriter auditWriter;

        public AuditingInvoiceRepository(IInvoiceRepository invoiceRepository, IAuditWriter auditWriter) {
            this.invoiceRepository = invoiceRepository;
            this.auditWriter = auditWriter;
        }

        public void Save(Invoice invoice) {
            auditWriter.WriteEntry("Invoice was written by a user.");
            invoiceRepository.Save(invoice);
        }
    }
}