using System;

namespace Wayne.Lib.MessageBus
{
    /// <summary>
    /// Wayne internal message bus. Topic-based publish and subscription. 
    /// Topic is a string with "/". When subscribing it is possible to enter "*" on a position,
    /// so for example topic filter "A/*/C" will match topic "A/B/C", "A/C/C" etc.
    /// </summary>
    public interface IBus
    {
        /// <summary>
        /// Publish a message on the bus.
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="message"></param>
        void Publish(string topic, object message);

        /// <summary>
        /// Subscribe to the bus. 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="topicFilter"></param>
        /// <param name="action"></param>
        /// <returns>A disposable object that is should be disposed when subscription should be ended.</returns>
        IDisposable Subscribe<T>(string topicFilter, Action<string, T> action);
    }
}