package org.antbear.jee.spring.jdbc;

import org.antbear.jee.spring.jdbc.dataaccess.CustomerDao;
import org.antbear.jee.spring.jdbc.dataaccess.OrderDao;
import org.antbear.jee.spring.jdbc.dataaccess.OrderPositionDao;
import org.antbear.jee.spring.jdbc.dataaccess.ProductDao;
import org.antbear.jee.spring.jdbc.domain.Customer;
import org.antbear.jee.spring.jdbc.domain.Order;
import org.antbear.jee.spring.jdbc.domain.OrderPosition;
import org.antbear.jee.spring.jdbc.domain.Product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class App {

    private final static Logger log = LoggerFactory.getLogger(App.class);

    @Autowired
    private CustomerDao customerDao;

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private OrderPositionDao orderPositionDao;

    @Autowired
    private ProductDao productDao;

    public void businessMethod() {
        for (final Customer customer : customerDao.findAll()) {
            log.debug(customer.toString());
            final List<Order> orders = orderDao.findByCustomer(customer.getId());
            for (final Order order : orders) {
                log.debug(order.toString());
                final List<OrderPosition> orderPositions = orderPositionDao.findByOrder(order.getId());
                for (final OrderPosition orderPosition : orderPositions) {
                    log.debug(orderPosition.toString());
                    final Product product = productDao.findById(orderPosition.getProductId());
                    log.debug(product.toString());
                }
            }
        }
    }
}
