// 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/Persistence.java
// public class Persistence {
// 
//     public static final ObjectMapper mapper = new ObjectMapper()
//             .setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
//             .setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE)
//             .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
//             .setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY)
//             .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
//             .enable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID)
//             .registerModule(new Jdk8Module())
//             .registerModule(new ParameterNamesModule())
//             .registerModule(new JavaTimeModule());
// 
//     public static final SerializationVersioning serialization = new SerializationVersioning(
//             current(Registered.class, "ReadyToStore v1", mapper::writeValueAsString, mapper::readValue),
//             current(Stored.class, "Stored v1", mapper::writeValueAsString, mapper::readValue),
//             current(Picked.class, "Picked v2", mapper::writeValueAsString, mapper::readValue),
//             obsolete(Picked.class, "Picked v1", Persistence::pickedFromV1),
//             current(Locked.class, "Locked v1", mapper::writeValueAsString, mapper::readValue),
//             current(Unlocked.class, "Unlocked v1", mapper::writeValueAsString, mapper::readValue),
//             current(Destroyed.class, "Destroyed v1", mapper::writeValueAsString, mapper::readValue)
//     );
// 
//     private static Picked pickedFromV1(String string, Class<Picked> type) throws Throwable {
//         JsonNode json = mapper.readTree(string);
//         return new Picked(
//                 new PaletteLabel(
//                         json.path("paletteLabel").path("id").asText(),
//                         json.path("paletteLabel").path("refNo").asText()
//                 ),
//                 json.path("user").asText(),
//                 new Location(json.path("lastKnownLocation").path("location").asText()),
//                 Location.onTheMove(json.path("user").asText())
//         );
//     }
// 
//     private Persistence() {
//     }
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Destroyed.java
// @Value
// public class Destroyed {
//     private final PaletteLabel paletteLabel;
// }


import lombok.AllArgsConstructor;
import lombok.Data;
import org.sql2o.Connection;
import org.sql2o.Query;
import org.sql2o.ResultSetIterable;
import org.sql2o.Sql2o;
import warehouse.PaletteLabel;
import warehouse.Persistence;
import warehouse.quality.Destroyed;
import java.time.Instant;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
package warehouse.products;



/**
 * Created by michal on 21.10.2017.
 */
@AllArgsConstructor
public class ProductStockSql2oEventsStore implements ProductStockEventStore {

    private final Sql2o sql2o;

    private final Predicate<Object> archiveUnit =
// 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/Persistence.java
// public class Persistence {
// 
//     public static final ObjectMapper mapper = new ObjectMapper()
//             .setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
//             .setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE)
//             .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
//             .setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY)
//             .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
//             .enable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID)
//             .registerModule(new Jdk8Module())
//             .registerModule(new ParameterNamesModule())
//             .registerModule(new JavaTimeModule());
// 
//     public static final SerializationVersioning serialization = new SerializationVersioning(
//             current(Registered.class, "ReadyToStore v1", mapper::writeValueAsString, mapper::readValue),
//             current(Stored.class, "Stored v1", mapper::writeValueAsString, mapper::readValue),
//             current(Picked.class, "Picked v2", mapper::writeValueAsString, mapper::readValue),
//             obsolete(Picked.class, "Picked v1", Persistence::pickedFromV1),
//             current(Locked.class, "Locked v1", mapper::writeValueAsString, mapper::readValue),
//             current(Unlocked.class, "Unlocked v1", mapper::writeValueAsString, mapper::readValue),
//             current(Destroyed.class, "Destroyed v1", mapper::writeValueAsString, mapper::readValue)
//     );
// 
//     private static Picked pickedFromV1(String string, Class<Picked> type) throws Throwable {
//         JsonNode json = mapper.readTree(string);
//         return new Picked(
//                 new PaletteLabel(
//                         json.path("paletteLabel").path("id").asText(),
//                         json.path("paletteLabel").path("refNo").asText()
//                 ),
//                 json.path("user").asText(),
//                 new Location(json.path("lastKnownLocation").path("location").asText()),
//                 Location.onTheMove(json.path("user").asText())
//         );
//     }
// 
//     private Persistence() {
//     }
// }
// 
// Path: warehouse-model/src/main/java/warehouse/quality/Destroyed.java
// @Value
// public class Destroyed {
//     private final PaletteLabel paletteLabel;
// }


// Path: warehouse-infrastructure/src/main/java/warehouse/products/ProductStockSql2oEventsStore.java
import lombok.AllArgsConstructor;
import lombok.Data;
import org.sql2o.Connection;
import org.sql2o.Query;
import org.sql2o.ResultSetIterable;
import org.sql2o.Sql2o;
import warehouse.PaletteLabel;
import warehouse.Persistence;
import warehouse.quality.Destroyed;
import java.time.Instant;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

package warehouse.products;



/**
 * Created by michal on 21.10.2017.
 */
@AllArgsConstructor
public class ProductStockSql2oEventsStore implements ProductStockEventStore {

    private final Sql2o sql2o;

    private final Predicate<Object> archiveUnit =
            event -> event instanceof Destroyed ||