// Path: cqrs-lib/src/main/java/se/citerus/cqrs/bookstore/command/CommandBus.java
// public interface CommandBus {
// 
//   void dispatch(Command command);
// 
//   <T extends CommandHandler> T register(T handler);
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/api/ActivateOrderRequest.java
// public class ActivateOrderRequest extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String orderId;
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/api/PlaceOrderRequest.java
// public class PlaceOrderRequest extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String orderId;
// 
//   @NotNull
//   public String customerName;
// 
//   @NotNull
//   public String customerEmail;
// 
//   @NotNull
//   public String customerAddress;
// 
//   @NotNull
//   public CartDto cart;
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/ActivateOrderCommand.java
// public class ActivateOrderCommand extends Command {
// 
//   public final OrderId orderId;
// 
//   public ActivateOrderCommand(OrderId orderId) {
//     checkArgument(orderId != null, "OrderId cannot be null");
//     this.orderId = orderId;
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/CommandFactory.java
// public class CommandFactory {
// 
//   public PlaceOrderCommand toCommand(PlaceOrderRequest request) {
//     List<OrderLine> itemsToOrder = getOrderLines(request.cart);
//     CustomerInformation customerInformation = getCustomerInformation(request);
//     long totalPrice = request.cart.totalPrice;
//     return new PlaceOrderCommand(new OrderId(request.orderId), customerInformation, itemsToOrder, totalPrice);
//   }
// 
//   public ActivateOrderCommand toCommand(ActivateOrderRequest request) {
//     return new ActivateOrderCommand(new OrderId(request.orderId));
//   }
// 
//   private List<OrderLine> getOrderLines(CartDto cart) {
//     List<OrderLine> itemsToOrder = new ArrayList<>();
//     for (LineItemDto lineItem : cart.lineItems) {
//       ProductId productId = new ProductId(lineItem.productId);
//       String title = lineItem.title;
//       int quantity = lineItem.quantity;
//       long price = lineItem.price;
//       itemsToOrder.add(new OrderLine(productId, title, quantity, price));
//     }
//     return itemsToOrder;
//   }
// 
//   private CustomerInformation getCustomerInformation(PlaceOrderRequest request) {
//     return new CustomerInformation(request.customerName, request.customerEmail, request.customerAddress);
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/PlaceOrderCommand.java
// public class PlaceOrderCommand extends Command {
// 
//   public final OrderId orderId;
//   public final CustomerInformation customerInformation;
//   public final List<OrderLine> orderLines;
//   public final long totalAmount;
// 
//   public PlaceOrderCommand(OrderId orderId, CustomerInformation customerInformation, List<OrderLine> orderLines, long totalAmount) {
//     checkArgument(orderId != null, "OrderId cannot be null");
//     checkArgument(customerInformation != null, "CustomerInformation cannot be null");
//     checkArgument(orderLines != null, "Items cannot be null");
//     checkArgument(!orderLines.isEmpty(), "Item list cannot be empty");
//     checkArgument(totalAmount > 0, "Total amount must be > 0");
//     this.orderId = orderId;
//     this.customerInformation = customerInformation;
//     this.orderLines = Collections.unmodifiableList(orderLines);
//     this.totalAmount = totalAmount;
//   }
// 
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.citerus.cqrs.bookstore.command.CommandBus;
import se.citerus.cqrs.bookstore.ordercontext.api.ActivateOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.api.PlaceOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.order.command.ActivateOrderCommand;
import se.citerus.cqrs.bookstore.ordercontext.order.command.CommandFactory;
import se.citerus.cqrs.bookstore.ordercontext.order.command.PlaceOrderCommand;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
package se.citerus.cqrs.bookstore.ordercontext.resource;




@Path("order-requests")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public class OrderResource {

  private final Logger logger = LoggerFactory.getLogger(getClass());
  private final CommandBus commandBus;
  private final CommandFactory commandFactory = new CommandFactory();

  public OrderResource(CommandBus commandBus) {
    this.commandBus = commandBus;
  }

  @POST
// Path: cqrs-lib/src/main/java/se/citerus/cqrs/bookstore/command/CommandBus.java
// public interface CommandBus {
// 
//   void dispatch(Command command);
// 
//   <T extends CommandHandler> T register(T handler);
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/api/ActivateOrderRequest.java
// public class ActivateOrderRequest extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String orderId;
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/api/PlaceOrderRequest.java
// public class PlaceOrderRequest extends TransportObject {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String orderId;
// 
//   @NotNull
//   public String customerName;
// 
//   @NotNull
//   public String customerEmail;
// 
//   @NotNull
//   public String customerAddress;
// 
//   @NotNull
//   public CartDto cart;
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/ActivateOrderCommand.java
// public class ActivateOrderCommand extends Command {
// 
//   public final OrderId orderId;
// 
//   public ActivateOrderCommand(OrderId orderId) {
//     checkArgument(orderId != null, "OrderId cannot be null");
//     this.orderId = orderId;
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/CommandFactory.java
// public class CommandFactory {
// 
//   public PlaceOrderCommand toCommand(PlaceOrderRequest request) {
//     List<OrderLine> itemsToOrder = getOrderLines(request.cart);
//     CustomerInformation customerInformation = getCustomerInformation(request);
//     long totalPrice = request.cart.totalPrice;
//     return new PlaceOrderCommand(new OrderId(request.orderId), customerInformation, itemsToOrder, totalPrice);
//   }
// 
//   public ActivateOrderCommand toCommand(ActivateOrderRequest request) {
//     return new ActivateOrderCommand(new OrderId(request.orderId));
//   }
// 
//   private List<OrderLine> getOrderLines(CartDto cart) {
//     List<OrderLine> itemsToOrder = new ArrayList<>();
//     for (LineItemDto lineItem : cart.lineItems) {
//       ProductId productId = new ProductId(lineItem.productId);
//       String title = lineItem.title;
//       int quantity = lineItem.quantity;
//       long price = lineItem.price;
//       itemsToOrder.add(new OrderLine(productId, title, quantity, price));
//     }
//     return itemsToOrder;
//   }
// 
//   private CustomerInformation getCustomerInformation(PlaceOrderRequest request) {
//     return new CustomerInformation(request.customerName, request.customerEmail, request.customerAddress);
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/PlaceOrderCommand.java
// public class PlaceOrderCommand extends Command {
// 
//   public final OrderId orderId;
//   public final CustomerInformation customerInformation;
//   public final List<OrderLine> orderLines;
//   public final long totalAmount;
// 
//   public PlaceOrderCommand(OrderId orderId, CustomerInformation customerInformation, List<OrderLine> orderLines, long totalAmount) {
//     checkArgument(orderId != null, "OrderId cannot be null");
//     checkArgument(customerInformation != null, "CustomerInformation cannot be null");
//     checkArgument(orderLines != null, "Items cannot be null");
//     checkArgument(!orderLines.isEmpty(), "Item list cannot be empty");
//     checkArgument(totalAmount > 0, "Total amount must be > 0");
//     this.orderId = orderId;
//     this.customerInformation = customerInformation;
//     this.orderLines = Collections.unmodifiableList(orderLines);
//     this.totalAmount = totalAmount;
//   }
// 
// }


// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/resource/OrderResource.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.citerus.cqrs.bookstore.command.CommandBus;
import se.citerus.cqrs.bookstore.ordercontext.api.ActivateOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.api.PlaceOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.order.command.ActivateOrderCommand;
import se.citerus.cqrs.bookstore.ordercontext.order.command.CommandFactory;
import se.citerus.cqrs.bookstore.ordercontext.order.command.PlaceOrderCommand;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

package se.citerus.cqrs.bookstore.ordercontext.resource;




@Path("order-requests")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public class OrderResource {

  private final Logger logger = LoggerFactory.getLogger(getClass());
  private final CommandBus commandBus;
  private final CommandFactory commandFactory = new CommandFactory();

  public OrderResource(CommandBus commandBus) {
    this.commandBus = commandBus;
  }

  @POST
  public void placeOrder(@Valid PlaceOrderRequest placeOrderRequest) {