using BookStore_DataAccess.context;
using BookStore_DataAccess.model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BookStore_DataAccess.repository
{
    public class UnitOfWork
    {
        private BookStoreDataModel bookStoreContext = new BookStoreDataModel();
        private IRepository<Book> bookRepository;
        private IRepository<Author> authorRepository;
        private IRepository<Publisher> publisherRepository;


        public IRepository<Author> AuthorRepository
        {
            get
            {
                if (this.authorRepository == null)
                {
                    this.authorRepository = new AuthorRepository(bookStoreContext);
                }
                return authorRepository;
            }
        }

        public IRepository<Book> BookRepository
        {
            get
            {
                if (this.bookRepository == null)
                {
                    this.bookRepository = new BookRepository(bookStoreContext);
                }
                return bookRepository;
            }
        }

        public IRepository<Publisher> PublisherRepository
        {
            get
            {
                if (this.publisherRepository == null)
                {
                    this.publisherRepository = new PublisherRepository(bookStoreContext);
                }
                return publisherRepository;
            }
        }

        public void Save()
        {
            bookStoreContext.SaveChanges();
        }

    }
}
