// Copyright (C) 2010-2013  MarketFactory, Inc. All Rights Reserved.
#ifndef __MFAPI_MFHANDLER__
#define __MFAPI_MFHANDLER__

namespace MFAPI {
class MFClient;
class SubscriptionEvent;
class MarketView;
class OrderReceived;
class OrderRejected;
class OrderSubmitted;
class OrderCanceled;
class OrderCancelRejected;
class TradeCapture;
class OrderDone;
class DropCopy;
class EventReport;
class ReplayDone;
class DateRollover;
class Batch;
class Heartbeat;

/**
 * An interface for callbacks of a market-data client.
 */
class MFHandler {
 public:
  // Destructor.
  virtual ~MFHandler() {}

  //--------------------------------------------------------------------------------
  // Connections

  /**
   * Called right after we start dispatching events, once per call to
   * client.run().
   */
  virtual void onStart(MFClient& client) = 0;

  /**
   * Called right before we stop dispatching events and return from
   * client.run().
   */
  virtual void onStop(MFClient& client) = 0;

  /**
   * Called when connection is broken unexpectedly; this signals that the
   * dispatcher is about to attempt to reconnect and if necessary fail over to
   * the secondary server, if one has been provided.
   */
  virtual void onDisconnect(MFClient& client) = 0;

  /**
   * Called right after a reconnection attempt succeeds. If reconnection
   * failed, the run() dispatcher will return with an error code.
   *
   * (Note: this is only used for failover. During connect()/close() there is
   * no active dispatcher, so there is no handler, so no corresponding
   * callback either.)
   */
  virtual void onConnect(MFClient& client) = 0;

  /**
   * Called with fast heartbeats containing feed status information.
   */
  virtual void onHeartbeat(const Heartbeat& heartbeat, MFClient& client) = 0;

  //--------------------------------------------------------------------------------
  // Subscriptions

  /**
   * Subscription Event: Called when the status of the subscription changes.
   */
  virtual void onSubscriptionEvent(const SubscriptionEvent& subscriptionEvent,
                                   MFClient& client) = 0;

  //--------------------------------------------------------------------------------
  // Market Data

  /**
   * Market Data Event: Called on new market-data updates.
   */
  virtual void onMarketData(const MarketView& marketData, MFClient& client) = 0;

  /**
   * Report Event: Called on new event report.
   */
  virtual void onEventReport(const EventReport& eventReport,
                             MFClient& client) = 0;

  /**
   * Date Rollover : Called on new date rollover upate.
   */
  virtual void onDateRollover(const DateRollover& eventReport,
                              MFClient& client) = 0;

  /**
   * Batch Complete Event: Called on completed batches.
   */
  virtual void onBatchComplete(const int batchDefID, MFClient& client) = 0;

  //--------------------------------------------------------------------------------
  // Trading

  /**
   * Trading Event: Callback that gets invoked when an Order is received by the
   * server.
   */
  virtual void onOrderReceived(const OrderReceived& orderReceived,
                               MFClient& client) = 0;

  /**
   * Trading Event: Callback that gets invoked when an Order is rejected.
   */
  virtual void onOrderRejected(const OrderRejected& orderRejected,
                               MFClient& client) = 0;

  /**
   * Trading Event: Callback that gets invoked when an Order is successfully
   * submitted.
   */
  virtual void onOrderSubmitted(const OrderSubmitted& orderSubmitted,
                                MFClient& client) = 0;

  /**
   * Trading Event: Callback that gets invoked when an Order is successfully
   * canceled.
   */
  virtual void onOrderCanceled(const OrderCanceled& orderCanceled,
                               MFClient& client) = 0;

  /**
   * Trading Event: Callback that gets invoked when an Order cancel is rejected.
   */
  virtual void onOrderCancelRejected(
      const OrderCancelRejected& orderCancelRejected, MFClient& client) = 0;

  /**
   * Trading Event: Callback that gets invoked on TradeCapture events
   */
  virtual void onTradeCapture(const TradeCapture& tradeCapture,
                              MFClient& client) = 0;

  /**
   * Trading Event: Callback that gets invoked when an Order is finished
   */
  virtual void onOrderDone(const OrderDone& orderDone, MFClient& client) = 0;

  /**
   * Drop Copy Trading Event: Callback that gets invoked on DropCopy events.
   */
  virtual void onDropCopy(const DropCopy& dropCopy, MFClient& client) = 0;

  /**
   * Replay Event: Callback that gets invoked after replay request has been
   * fully processed.
   */
  virtual void onReplayDone(const ReplayDone& replayDone, MFClient& client) = 0;
};
}
#endif
// InclKwds: MFHandler
