// 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/publisher-contract-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/publishercontract/domain/PublisherContract.java
// public class PublisherContract extends AggregateRoot<PublisherContractId> {
// 
//   private double feePercentage;
//   private long limit;
//   private long accumulatedFee;
// 
//   public void register(PublisherContractId publisherContractId, String name, double feePercentage, long limit) {
//     assertHasNotBeenRegistered();
//     applyChange(new PublisherContractRegisteredEvent(publisherContractId, nextVersion(), now(), name, feePercentage, limit));
//   }
// 
//   public void registerPurchase(ProductId productId, long unitPrice, int quantity) {
//     long purchaseAmount = unitPrice * quantity;
//     AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount);
//     applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee()));
//   }
// 
//   private void assertHasNotBeenRegistered() {
//     checkState(id() == null, "Contract has already been registered");
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(PublisherContractRegisteredEvent event) {
//     this.feePercentage = event.feePercentage;
//     this.limit = event.limit;
//     this.accumulatedFee = 0;
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(PurchaseRegisteredEvent event) {
//     this.accumulatedFee = event.accumulatedFee;
//   }
// 
// }


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.publishercontract.domain.PublisherContract;
package se.citerus.cqrs.bookstore.ordercontext.publishercontract.command;


public class PublisherContractCommandHandler implements CommandHandler {

  private final Repository repository;

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

  @Subscribe
  public void handle(RegisterPublisherContractCommand command) {
// 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/publisher-contract-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/publishercontract/domain/PublisherContract.java
// public class PublisherContract extends AggregateRoot<PublisherContractId> {
// 
//   private double feePercentage;
//   private long limit;
//   private long accumulatedFee;
// 
//   public void register(PublisherContractId publisherContractId, String name, double feePercentage, long limit) {
//     assertHasNotBeenRegistered();
//     applyChange(new PublisherContractRegisteredEvent(publisherContractId, nextVersion(), now(), name, feePercentage, limit));
//   }
// 
//   public void registerPurchase(ProductId productId, long unitPrice, int quantity) {
//     long purchaseAmount = unitPrice * quantity;
//     AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount);
//     applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee()));
//   }
// 
//   private void assertHasNotBeenRegistered() {
//     checkState(id() == null, "Contract has already been registered");
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(PublisherContractRegisteredEvent event) {
//     this.feePercentage = event.feePercentage;
//     this.limit = event.limit;
//     this.accumulatedFee = 0;
//   }
// 
//   @SuppressWarnings("UnusedDeclaration")
//   void handleEvent(PurchaseRegisteredEvent event) {
//     this.accumulatedFee = event.accumulatedFee;
//   }
// 
// }


// Path: order-context-parent/publisher-contract-command/src/main/java/se/citerus/cqrs/bookstore/ordercontext/publishercontract/command/PublisherContractCommandHandler.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.publishercontract.domain.PublisherContract;

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


public class PublisherContractCommandHandler implements CommandHandler {

  private final Repository repository;

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

  @Subscribe
  public void handle(RegisterPublisherContractCommand command) {
    PublisherContract contract = new PublisherContract();