// Path: cqrs-lib/src/main/java/se/citerus/cqrs/bookstore/command/CommandHandler.java
// public interface CommandHandler {
// }
// 
// Path: cqrs-lib/src/main/java/se/citerus/cqrs/bookstore/domain/Repository.java
// public interface Repository {
// 
//   <AR extends AggregateRoot> void save(AR aggregateRoot);
// 
//   <AR extends AggregateRoot, ID extends GenericId> AR load(ID id, Class<AR> aggregateType);
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/domain/Order.java
// public class Order extends AggregateRoot<OrderId> {
// 
//   private OrderStatus status;
// 
//   public void place(OrderId orderId, CustomerInformation customerInformation, List<OrderLine> orderLines, long totalAmount) {
//     assertHasNotBeenPlaced();
//     assertMoreThanZeroOrderLines(orderLines);
//     applyChange(new OrderPlacedEvent(orderId, nextVersion(), now(), toCustomerInformation(customerInformation),
//         toOrderLines(orderLines), totalAmount));
//   }
// 
//   public void activate() {
//     if (orderIsPlaced()) {
//       applyChange(new OrderActivatedEvent(id(), nextVersion(), now()));
//     }
//   }
// 
//   private boolean orderIsPlaced() {
//     return status == OrderStatus.PLACED;
//   }
// 
//   private void assertMoreThanZeroOrderLines(List<OrderLine> orderLines) {
//     checkArgument(!orderLines.isEmpty(), "Cannot place an order without any order lines");
//   }
// 
//   private void assertHasNotBeenPlaced() {
//     checkState(id() == null, "Order has already been placed");
//   }
// 
//   private se.citerus.cqrs.bookstore.ordercontext.order.CustomerInformation toCustomerInformation(
//       CustomerInformation customerInformation) {
//     return new se.citerus.cqrs.bookstore.ordercontext.order.CustomerInformation(
//         customerInformation.customerName, customerInformation.email, customerInformation.address);
//   }
// 
//   private List<se.citerus.cqrs.bookstore.ordercontext.order.OrderLine> toOrderLines(List<OrderLine> orderLines) {
//     List<se.citerus.cqrs.bookstore.ordercontext.order.OrderLine> list = new ArrayList<>();
//     for (OrderLine orderLine : orderLines) {
//       list.add(new se.citerus.cqrs.bookstore.ordercontext.order.OrderLine(orderLine.productId, orderLine.title,
//           orderLine.quantity, orderLine.unitPrice));
//     }
//     return list;
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(OrderPlacedEvent event) {
//     this.status = OrderStatus.PLACED;
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(OrderActivatedEvent event) {
//     this.status = OrderStatus.ACTIVATED;
//   }
// 
// }


import com.google.common.eventbus.Subscribe;
import se.citerus.cqrs.bookstore.command.CommandHandler;
import se.citerus.cqrs.bookstore.domain.Repository;
import se.citerus.cqrs.bookstore.ordercontext.order.domain.Order;
package se.citerus.cqrs.bookstore.ordercontext.order.command;


public class OrderCommandHandler implements CommandHandler {

  private final Repository repository;

  public OrderCommandHandler(Repository repository) {
    this.repository = repository;
  }

  @Subscribe
  public void handle(PlaceOrderCommand command) {
    Order order = new Order();
    order.place(command.orderId, command.customerInformation, command.orderLines, command.totalAmount);
    repository.save(order);
  }

// Path: cqrs-lib/src/main/java/se/citerus/cqrs/bookstore/command/CommandHandler.java
// public interface CommandHandler {
// }
// 
// Path: cqrs-lib/src/main/java/se/citerus/cqrs/bookstore/domain/Repository.java
// public interface Repository {
// 
//   <AR extends AggregateRoot> void save(AR aggregateRoot);
// 
//   <AR extends AggregateRoot, ID extends GenericId> AR load(ID id, Class<AR> aggregateType);
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/domain/Order.java
// public class Order extends AggregateRoot<OrderId> {
// 
//   private OrderStatus status;
// 
//   public void place(OrderId orderId, CustomerInformation customerInformation, List<OrderLine> orderLines, long totalAmount) {
//     assertHasNotBeenPlaced();
//     assertMoreThanZeroOrderLines(orderLines);
//     applyChange(new OrderPlacedEvent(orderId, nextVersion(), now(), toCustomerInformation(customerInformation),
//         toOrderLines(orderLines), totalAmount));
//   }
// 
//   public void activate() {
//     if (orderIsPlaced()) {
//       applyChange(new OrderActivatedEvent(id(), nextVersion(), now()));
//     }
//   }
// 
//   private boolean orderIsPlaced() {
//     return status == OrderStatus.PLACED;
//   }
// 
//   private void assertMoreThanZeroOrderLines(List<OrderLine> orderLines) {
//     checkArgument(!orderLines.isEmpty(), "Cannot place an order without any order lines");
//   }
// 
//   private void assertHasNotBeenPlaced() {
//     checkState(id() == null, "Order has already been placed");
//   }
// 
//   private se.citerus.cqrs.bookstore.ordercontext.order.CustomerInformation toCustomerInformation(
//       CustomerInformation customerInformation) {
//     return new se.citerus.cqrs.bookstore.ordercontext.order.CustomerInformation(
//         customerInformation.customerName, customerInformation.email, customerInformation.address);
//   }
// 
//   private List<se.citerus.cqrs.bookstore.ordercontext.order.OrderLine> toOrderLines(List<OrderLine> orderLines) {
//     List<se.citerus.cqrs.bookstore.ordercontext.order.OrderLine> list = new ArrayList<>();
//     for (OrderLine orderLine : orderLines) {
//       list.add(new se.citerus.cqrs.bookstore.ordercontext.order.OrderLine(orderLine.productId, orderLine.title,
//           orderLine.quantity, orderLine.unitPrice));
//     }
//     return list;
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(OrderPlacedEvent event) {
//     this.status = OrderStatus.PLACED;
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(OrderActivatedEvent event) {
//     this.status = OrderStatus.ACTIVATED;
//   }
// 
// }


// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/OrderCommandHandler.java
import com.google.common.eventbus.Subscribe;
import se.citerus.cqrs.bookstore.command.CommandHandler;
import se.citerus.cqrs.bookstore.domain.Repository;
import se.citerus.cqrs.bookstore.ordercontext.order.domain.Order;

package se.citerus.cqrs.bookstore.ordercontext.order.command;


public class OrderCommandHandler implements CommandHandler {

  private final Repository repository;

  public OrderCommandHandler(Repository repository) {
    this.repository = repository;
  }

  @Subscribe
  public void handle(PlaceOrderCommand command) {
    Order order = new Order();
    order.place(command.orderId, command.customerInformation, command.orderLines, command.totalAmount);
    repository.save(order);
  }

  @Subscribe