using System;
using System.Collections.ObjectModel;
using System.Linq;
using DatabaseEditor.BL.Models;
using DatabaseEditor.DAL.Entities;

namespace DatabaseEditor.BL
{
    public class Mapper
    {
        public AuthorListModel MapEntityToListModel(Author authorEntity)
        {
            return new AuthorListModel()
            {
                Id = authorEntity.AuthorId,
                Name = authorEntity.Name,
                Surname = authorEntity.Surname
            };
        }

        public BookListModel MapEntityToListModel(Book bookEntity)
        {
            return new BookListModel()
            {
                Id = bookEntity.BookId,
                ISBN = bookEntity.ISBN,
                Name = bookEntity.Name,
                Pages = bookEntity.Pages,
                Year = bookEntity.Year
            };
        }

        public BookDetailModel MapEntityToDetailModel(Book bookEntity)
        {
            return new BookDetailModel()
            {
                Id = bookEntity.BookId,
                ISBN = bookEntity.ISBN,
                Name = bookEntity.Name,
                Pages = bookEntity.Pages,
                Year = bookEntity.Year,
                Authors = new ObservableCollection<AuthorListModel>(bookEntity.Authors.Select(MapEntityToListModel))
            };
        }

        public AuthorDetialModel MapEntityToDetailModel(Author authorEntity)
        {
            return new AuthorDetialModel()
            {
                Id = authorEntity.AuthorId,
                Name = authorEntity.Name,
                Surname = authorEntity.Surname,
                Books = new ObservableCollection<BookListModel>(authorEntity.Books.Select(MapEntityToListModel))
            };
        }
    }
}
