// 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/CartDto.java
// public class CartDto {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String cartId;
// 
//   @Min(1)
//   public long totalPrice;
// 
//   @Min(1)
//   public int totalQuantity;
// 
//   @NotNull
//   @NotEmpty
//   public List<LineItemDto> lineItems;
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/api/LineItemDto.java
// public class LineItemDto {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String productId;
// 
//   @NotNull
//   public String title;
// 
//   @Min(1)
//   public long price;
// 
//   @Min(1)
//   public int quantity;
// 
//   @Min(1)
//   public long totalPrice;
// 
// }
// 
// 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/eventbus-contract/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/OrderId.java
// public class OrderId extends GenericId {
// 
//   public OrderId(@JsonProperty("id") String id) {
//     super(id);
//   }
// 
//   public static OrderId randomId() {
//     return new OrderId(UUID.randomUUID().toString());
//   }
// 
// }
// 
// Path: order-context-parent/eventbus-contract/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/ProductId.java
// public class ProductId extends GenericId {
// 
//   public ProductId(@JsonProperty("id") String id) {
//     super(id);
//   }
// 
//   public static ProductId randomId() {
//     return new ProductId(UUID.randomUUID().toString());
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/domain/CustomerInformation.java
// public class CustomerInformation extends ValueObject {
// 
//   public final String customerName;
//   public final String email;
//   public final String address;
// 
//   public CustomerInformation(String customerName, String email, String address) {
//     this.customerName = customerName;
//     this.email = email;
//     this.address = address;
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/domain/OrderLine.java
// public class OrderLine extends ValueObject {
// 
//   public final ProductId productId;
//   public final String title;
//   public final int quantity;
//   public final long unitPrice;
// 
//   public OrderLine(ProductId productId, String title, int quantity, long unitPrice) {
//     this.productId = productId;
//     this.title = title;
//     this.quantity = quantity;
//     this.unitPrice = unitPrice;
//   }
// 
// }


import se.citerus.cqrs.bookstore.ordercontext.api.ActivateOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.api.CartDto;
import se.citerus.cqrs.bookstore.ordercontext.api.LineItemDto;
import se.citerus.cqrs.bookstore.ordercontext.api.PlaceOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.order.OrderId;
import se.citerus.cqrs.bookstore.ordercontext.order.ProductId;
import se.citerus.cqrs.bookstore.ordercontext.order.domain.CustomerInformation;
import se.citerus.cqrs.bookstore.ordercontext.order.domain.OrderLine;
import java.util.ArrayList;
import java.util.List;
package se.citerus.cqrs.bookstore.ordercontext.order.command;



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;
  }

// 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/CartDto.java
// public class CartDto {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String cartId;
// 
//   @Min(1)
//   public long totalPrice;
// 
//   @Min(1)
//   public int totalQuantity;
// 
//   @NotNull
//   @NotEmpty
//   public List<LineItemDto> lineItems;
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/api/LineItemDto.java
// public class LineItemDto {
// 
//   @NotEmpty
//   @Pattern(regexp = ID_PATTERN)
//   public String productId;
// 
//   @NotNull
//   public String title;
// 
//   @Min(1)
//   public long price;
// 
//   @Min(1)
//   public int quantity;
// 
//   @Min(1)
//   public long totalPrice;
// 
// }
// 
// 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/eventbus-contract/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/OrderId.java
// public class OrderId extends GenericId {
// 
//   public OrderId(@JsonProperty("id") String id) {
//     super(id);
//   }
// 
//   public static OrderId randomId() {
//     return new OrderId(UUID.randomUUID().toString());
//   }
// 
// }
// 
// Path: order-context-parent/eventbus-contract/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/ProductId.java
// public class ProductId extends GenericId {
// 
//   public ProductId(@JsonProperty("id") String id) {
//     super(id);
//   }
// 
//   public static ProductId randomId() {
//     return new ProductId(UUID.randomUUID().toString());
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/domain/CustomerInformation.java
// public class CustomerInformation extends ValueObject {
// 
//   public final String customerName;
//   public final String email;
//   public final String address;
// 
//   public CustomerInformation(String customerName, String email, String address) {
//     this.customerName = customerName;
//     this.email = email;
//     this.address = address;
//   }
// 
// }
// 
// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/domain/OrderLine.java
// public class OrderLine extends ValueObject {
// 
//   public final ProductId productId;
//   public final String title;
//   public final int quantity;
//   public final long unitPrice;
// 
//   public OrderLine(ProductId productId, String title, int quantity, long unitPrice) {
//     this.productId = productId;
//     this.title = title;
//     this.quantity = quantity;
//     this.unitPrice = unitPrice;
//   }
// 
// }


// Path: order-context-parent/order-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/order/command/CommandFactory.java
import se.citerus.cqrs.bookstore.ordercontext.api.ActivateOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.api.CartDto;
import se.citerus.cqrs.bookstore.ordercontext.api.LineItemDto;
import se.citerus.cqrs.bookstore.ordercontext.api.PlaceOrderRequest;
import se.citerus.cqrs.bookstore.ordercontext.order.OrderId;
import se.citerus.cqrs.bookstore.ordercontext.order.ProductId;
import se.citerus.cqrs.bookstore.ordercontext.order.domain.CustomerInformation;
import se.citerus.cqrs.bookstore.ordercontext.order.domain.OrderLine;
import java.util.ArrayList;
import java.util.List;

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



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) {