// Path: warehouse-infrastructure/src/main/java/warehouse/EventMappings.java
// public class EventMappings {
// 
//     private ProductStockAgentRepository stocks;
//     private FifoRepository fifo;
//     private OpsSupport support;
// 
//     public ExternalEvents externalEvents() {
//         return new ExternalEvents();
//     }
// 
//     public ProductStock.EventsContract productStocks() {
//         return new ProductStocks();
//     }
// 
//     @AllArgsConstructor
//     public class ExternalEvents {
// 
//         public void emit(Locked event) {
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
// 
//         public void emit(Unlocked event) {
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
// 
//         public void emit(Destroyed event) {
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
// 
//         public void emit(Delivered event) {
//             stocks.get(event.getPaletteLabel().getRefNo())
//                     .ifPresent(productStock -> productStock.delivered(event)
//                             .handle((object, throwable) -> support.appliedExternalEventOnProductStock(productStock, event, throwable))
//                     );
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
//     }
// 
//     @AllArgsConstructor
//     private class ProductStocks implements ProductStock.EventsContract {
// 
//         @Override
//         public void emit(Registered event) {
//             async(() -> fifo.handle(event.getPaletteLabel().getRefNo(), event));
//         }
// 
//         @Override
//         public void emit(Stored event) {
//         }
// 
//         @Override
//         public void emit(Picked event) {
//         }
// 
//         @Override
//         public void emit(Locked event) {
//             async(() -> fifo.handle(event.getPaletteLabel().getRefNo(), event));
//         }
//     }
// 
//     void dependencies(ProductStockAgentRepository stocks, FifoRepository fifo, OpsSupport support) {
//         this.stocks = stocks;
//         this.fifo = fifo;
//         this.support = support;
//     }
// 
//     void async(Runnable handler) {
//         CompletableFuture.runAsync(handler);
//     }
// }
// 
// Path: warehouse-model/src/main/java/warehouse/PaletteLabel.java
// @Value
// public class PaletteLabel {
//     private final String id;
//     private final String refNo;
// 
//     @Override
//     public String toString() {
//         return id;
//     }
// }
// 
// Path: warehouse-infrastructure/src/main/java/warehouse/products/ProductStockEventStore.java
// public interface ProductStockEventStore {
//     EventId persist(PaletteLabel storageUnit, Object event);
// 
//     List<Object> readEventsInStock(String refNo);
//     List<Object> readEventsSince(String refNo, EventId since);
// 
//     @Value
//     @ToString(of = "id")
//     class EventId {
//         Object id;
//     }
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Destroyed.java
// @Value
// public class Destroyed {
//     private final PaletteLabel paletteLabel;
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Locked.java
// @Value
// public class Locked {
//     private final PaletteLabel paletteLabel;
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Unlocked.java
// @Value
// public class Unlocked {
//     private final PaletteLabel paletteLabel;
//     private final int recovered;
//     private final int scraped;
// }


import warehouse.EventMappings;
import warehouse.PaletteLabel;
import warehouse.products.ProductStockEventStore;
import warehouse.quality.Destroyed;
import warehouse.quality.Locked;
import warehouse.quality.Unlocked;
package quality;


/**
 * Created by michal on 20.08.2016.
 */
public class QualityReportService {

    private final ProductStockEventStore stocks;
    private final EventMappings.ExternalEvents events;

// Path: warehouse-infrastructure/src/main/java/warehouse/EventMappings.java
// public class EventMappings {
// 
//     private ProductStockAgentRepository stocks;
//     private FifoRepository fifo;
//     private OpsSupport support;
// 
//     public ExternalEvents externalEvents() {
//         return new ExternalEvents();
//     }
// 
//     public ProductStock.EventsContract productStocks() {
//         return new ProductStocks();
//     }
// 
//     @AllArgsConstructor
//     public class ExternalEvents {
// 
//         public void emit(Locked event) {
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
// 
//         public void emit(Unlocked event) {
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
// 
//         public void emit(Destroyed event) {
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
// 
//         public void emit(Delivered event) {
//             stocks.get(event.getPaletteLabel().getRefNo())
//                     .ifPresent(productStock -> productStock.delivered(event)
//                             .handle((object, throwable) -> support.appliedExternalEventOnProductStock(productStock, event, throwable))
//                     );
//             fifo.handle(event.getPaletteLabel().getRefNo(), event);
//         }
//     }
// 
//     @AllArgsConstructor
//     private class ProductStocks implements ProductStock.EventsContract {
// 
//         @Override
//         public void emit(Registered event) {
//             async(() -> fifo.handle(event.getPaletteLabel().getRefNo(), event));
//         }
// 
//         @Override
//         public void emit(Stored event) {
//         }
// 
//         @Override
//         public void emit(Picked event) {
//         }
// 
//         @Override
//         public void emit(Locked event) {
//             async(() -> fifo.handle(event.getPaletteLabel().getRefNo(), event));
//         }
//     }
// 
//     void dependencies(ProductStockAgentRepository stocks, FifoRepository fifo, OpsSupport support) {
//         this.stocks = stocks;
//         this.fifo = fifo;
//         this.support = support;
//     }
// 
//     void async(Runnable handler) {
//         CompletableFuture.runAsync(handler);
//     }
// }
// 
// Path: warehouse-model/src/main/java/warehouse/PaletteLabel.java
// @Value
// public class PaletteLabel {
//     private final String id;
//     private final String refNo;
// 
//     @Override
//     public String toString() {
//         return id;
//     }
// }
// 
// Path: warehouse-infrastructure/src/main/java/warehouse/products/ProductStockEventStore.java
// public interface ProductStockEventStore {
//     EventId persist(PaletteLabel storageUnit, Object event);
// 
//     List<Object> readEventsInStock(String refNo);
//     List<Object> readEventsSince(String refNo, EventId since);
// 
//     @Value
//     @ToString(of = "id")
//     class EventId {
//         Object id;
//     }
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Destroyed.java
// @Value
// public class Destroyed {
//     private final PaletteLabel paletteLabel;
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Locked.java
// @Value
// public class Locked {
//     private final PaletteLabel paletteLabel;
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Unlocked.java
// @Value
// public class Unlocked {
//     private final PaletteLabel paletteLabel;
//     private final int recovered;
//     private final int scraped;
// }


// Path: warehouse-infrastructure/src/main/java/quality/QualityReportService.java
import warehouse.EventMappings;
import warehouse.PaletteLabel;
import warehouse.products.ProductStockEventStore;
import warehouse.quality.Destroyed;
import warehouse.quality.Locked;
import warehouse.quality.Unlocked;

package quality;


/**
 * Created by michal on 20.08.2016.
 */
public class QualityReportService {

    private final ProductStockEventStore stocks;
    private final EventMappings.ExternalEvents events;

    public QualityReportService(ProductStockEventStore stocks, EventMappings mappings) {