#ifndef __Subscription_h__
#define __Subscription_h__

#include "MString.h"
#include "SessionFilter.h"
#include "SubscriptionHandler.h"
#include "ZString.h"
#include <string>
#include <vector>

namespace core {

   class TCPSession;

   class Subscription {

   public:
      Subscription(coreutils::MString id, coreutils::MString mode = "*AUTHOR");
      Subscription(coreutils::MString id, coreutils::MString owner, coreutils::MString mode);
      Subscription(coreutils::MString id, coreutils::MString owner, coreutils::MString ownership, coreutils::MString mode, SubscriptionHandler *handler, coreutils::MString selection, coreutils::MString time);
      virtual ~Subscription();

      int subscribe(TCPSession &session);
      int unsubscribe(TCPSession &session);

      virtual int process(coreutils::ZString &request, std::stringstream &out, TCPSession &session);

      virtual int onSubscribe(TCPSession &session);

      int event(std::stringstream &out);
      bool subscriptionOwner(coreutils::MString owner, coreutils::MString selection);
      bool ifSubscriber(TCPSession &session);

      bool subInvite(TCPSession &session);

      void sendToAll(std::stringstream &data, TCPSession &sender);
      void sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter);

      coreutils::MString id;
      coreutils::MString mode;
      coreutils::MString owner;
      coreutils::MString subscriptionOwners;
      coreutils::MString selectionOfOwnerForSubscription;
      coreutils::MString will;
      coreutils::MString ownership;
      coreutils::MString timer;
      SubscriptionHandler *handler;

      std::vector<TCPSession *> subscribers;

   };
}

#endif
