// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
// 
//     List<Book> findByTitle(String title);
//     List<Book> findByReleaseDate(LocalDate releaseDate);
// 
// }
// 
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
//     void save(SequenceId sequenceId);
// 
//     long getNextSequenceId(String key);
// }
// 
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
// 
//     UserAccount findByUsername(String username);
// }
// 
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
//     public static final String BOOK_COLLECTION = "books";
//     private static final String BOOK_NOT_FOUND_MSG = "Book not found";
// 
//     @Autowired
//     private BookRepository bookRepository;
// 
//     @Autowired
//     private SequenceIdRepository sequenceIdRepository;
// 
//     @Override
//     public List<Book> findAll() {
//         return bookRepository.findAll();
//     }
// 
//     @Override
//     public Book save(Book book) {
//         return bookRepository.save(book);
//     }
// 
//     @Override
//     public Book findOne(Long id) {
//         Optional<Book> result = bookRepository.findById(id);
//         if (!result.isPresent()) {
//             throw new NotFoundException(BOOK_NOT_FOUND_MSG);
//         }
//         return result.get();
//     }
// 
//     @Override
//     public void delete(Long id) {
//         bookRepository.deleteById(id);
//     }
// 
//     @Override
//     public Book create(Book book) {
//         Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
//         book.setId(id);
// 
//         return bookRepository.save(book);
//     }
// 
//     @Override
//     public List<Book> findByTitle(String title) {
//         return bookRepository.findByTitle(title);
//     }
// 
//     @Override
//     public List<Book> findByReleaseDate(LocalDate releaseDate) {
//         return bookRepository.findByReleaseDate(releaseDate);
//     }
// }


import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;

    public void fillDBData() {
        log.info("Filling DB data...");
        fillDBUsersData();
        fillDBBooksData();
        log.info("DB filled with data.");
    }

    private void fillDBUsersData() {
        sequenceRepository.save(new SequenceId()
                .setId(USERACCOUNTS_COLLECTION)
                .setSeq(USERACCOUNTS_INITIAL_SEQUENCE)
        );
        userAccountRepository.deleteAll();
        Arrays.asList(
                new UserAccount()
                        .setId(USER_ID_1)
                        .setUsername(USER)
                        .setPassword(passwordEncoder.encode(PASSWORD_USER))
                        .setUserType(UserAccountType.REST_USER),
                new UserAccount()
                        .setId(USER_ID_2)
                        .setUsername(ADMIN)
                        .setPassword(passwordEncoder.encode(PASSWORD_ADMIN))
                        .setUserType(UserAccountType.ADMIN_USER))
                .forEach(userAccountRepository::save);
    }

    private void fillDBBooksData() {
        sequenceRepository.save(new SequenceId()
// Path: src/main/java/com/edwise/completespring/repositories/BookRepository.java
// public interface BookRepository extends MongoRepository<Book, Long> {
// 
//     List<Book> findByTitle(String title);
//     List<Book> findByReleaseDate(LocalDate releaseDate);
// 
// }
// 
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
//     void save(SequenceId sequenceId);
// 
//     long getNextSequenceId(String key);
// }
// 
// Path: src/main/java/com/edwise/completespring/repositories/UserAccountRepository.java
// public interface UserAccountRepository extends MongoRepository<UserAccount, Long> {
// 
//     UserAccount findByUsername(String username);
// }
// 
// Path: src/main/java/com/edwise/completespring/services/impl/BookServiceImpl.java
// @Service
// public class BookServiceImpl implements BookService {
//     public static final String BOOK_COLLECTION = "books";
//     private static final String BOOK_NOT_FOUND_MSG = "Book not found";
// 
//     @Autowired
//     private BookRepository bookRepository;
// 
//     @Autowired
//     private SequenceIdRepository sequenceIdRepository;
// 
//     @Override
//     public List<Book> findAll() {
//         return bookRepository.findAll();
//     }
// 
//     @Override
//     public Book save(Book book) {
//         return bookRepository.save(book);
//     }
// 
//     @Override
//     public Book findOne(Long id) {
//         Optional<Book> result = bookRepository.findById(id);
//         if (!result.isPresent()) {
//             throw new NotFoundException(BOOK_NOT_FOUND_MSG);
//         }
//         return result.get();
//     }
// 
//     @Override
//     public void delete(Long id) {
//         bookRepository.deleteById(id);
//     }
// 
//     @Override
//     public Book create(Book book) {
//         Long id = sequenceIdRepository.getNextSequenceId(BOOK_COLLECTION);
//         book.setId(id);
// 
//         return bookRepository.save(book);
//     }
// 
//     @Override
//     public List<Book> findByTitle(String title) {
//         return bookRepository.findByTitle(title);
//     }
// 
//     @Override
//     public List<Book> findByReleaseDate(LocalDate releaseDate) {
//         return bookRepository.findByReleaseDate(releaseDate);
//     }
// }


// Path: src/main/java/com/edwise/completespring/dbutils/DataLoader.java
import com.edwise.completespring.entities.*;
import com.edwise.completespring.repositories.BookRepository;
import com.edwise.completespring.repositories.SequenceIdRepository;
import com.edwise.completespring.repositories.UserAccountRepository;
import com.edwise.completespring.services.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;


    public void fillDBData() {
        log.info("Filling DB data...");
        fillDBUsersData();
        fillDBBooksData();
        log.info("DB filled with data.");
    }

    private void fillDBUsersData() {
        sequenceRepository.save(new SequenceId()
                .setId(USERACCOUNTS_COLLECTION)
                .setSeq(USERACCOUNTS_INITIAL_SEQUENCE)
        );
        userAccountRepository.deleteAll();
        Arrays.asList(
                new UserAccount()
                        .setId(USER_ID_1)
                        .setUsername(USER)
                        .setPassword(passwordEncoder.encode(PASSWORD_USER))
                        .setUserType(UserAccountType.REST_USER),
                new UserAccount()
                        .setId(USER_ID_2)
                        .setUsername(ADMIN)
                        .setPassword(passwordEncoder.encode(PASSWORD_ADMIN))
                        .setUserType(UserAccountType.ADMIN_USER))
                .forEach(userAccountRepository::save);
    }

    private void fillDBBooksData() {
        sequenceRepository.save(new SequenceId()
                .setId(BookServiceImpl.BOOK_COLLECTION)