content: package com.bookstore.service;
  
  import com.bookstore.entity.Author;
  import com.bookstore.entity.Book;
  import com.bookstore.entity.Ebook;
  import com.bookstore.entity.Paperback;
  import com.bookstore.repository.AuthorRepository;
  import com.bookstore.visitor.Visitor;
  
  import org.springframework.stereotype.Service;
  
  @Service
  public class BookstoreService {
      private final AuthorRepository authorRepository;
      private final VisitorService visitorService;
  
      public BookstoreService(AuthorRepository authorRepository, VisitorService visitorService) {
          this.authorRepository = authorRepository;
          this.visitorService = visitorService;
      }
  
      public void persistAuthorWithBooks() {
          Author author = new Author();
          author.setName("Alicia Tom");
          author.setAge(38);
          author.setGenre("Anthology");
  
          Book book = new Book();
          book.setIsbn("001-AT");
          book.setTitle("The book of swords");
  
          Paperback paperback = new Paperback();
          paperback.setIsbn("002-AT");
          paperback.setTitle("The beatles anthology");
          paperback.setSizeIn("7.5 x 1.3 x 9.2");
          paperback.setWeightLbs("2.7");
  
          Ebook ebook = new Ebook();
          ebook.setIsbn("003-AT");
          ebook.setTitle("Anthology myths");
          ebook.setFormat("kindle");
  
          //   author.addBook(book); // use addBook() helper
          author.addBook(paperback);
          author.addBook(ebook);
  
          authorRepository.save(author);
      }
  
      public void applyVisitor(Class<? extends Visitor> clazzVisitor) {
          visitorService.accept(clazzVisitor);
      }
  }