import java.util.List;
import java.util.stream.Collectors;

@Component
public class BookstoreOrderDao {
    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public BookstoreOrderDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public List<BookstoreOrder> getOrdersByCustomer(Long customerId) {
        // Code to get all orders by customer
    }

    public List<BookstoreOrder> getOrdersByCustomerAndAuthor(Long customerId, String authorName) {
        List<BookstoreOrder> customerOrders = getOrdersByCustomer(customerId);

        // Filter orders by author name
        List<BookstoreOrder> ordersByAuthor = customerOrders.stream()
            .filter(order -> order.getBooks().stream()
                    .anyMatch(book -> book.getAuthors().stream()
                            .anyMatch(author -> author.getName().equals(authorName))))
            .collect(Collectors.toList());

        return ordersByAuthor;
    }
}