using System;
using Wayne.Lib;

namespace Wayne.ForecourtControl.OptBridge
{
    /// <summary>
    /// Root object for the Opt communication using a application-layer bridge. The interface provides functionality to 
    /// get access to single Opts, and change the configuration.
    /// </summary>
    public interface IOptBridge : IConnectable, IIdentifiableEntity, IDisposable
    {
        #region Properties

        /// <summary>
        /// Collection of the currently configured Opts.
        /// </summary>
        System.Collections.ObjectModel.ReadOnlyCollection<IOpt> Opts { get;}

        /// <summary>
        /// The Client id that was specified in the connection string when connecting.
        /// </summary>
        int ClientId { get;}

        /// <summary>
        /// The Client name that was specified in the connection string when connecting.
        /// </summary>
        string ClientName { get;}

        #endregion

        #region Events

        /// <summary>
        /// Event that notifies clients that a Opt has been added or removed.
        /// </summary>
        event EventHandler OnConfigurationChanged;

        #endregion

        #region Methods

        /// <summary>
        /// Configure that the specified opt should be handled and polled. If the request completes sucessfully, the new 
        /// Opt is added to the Opts collection.
        /// </summary>
        /// <param name="optId"></param>
        /// <param name="requestCompleted"></param>
        /// <param name="userToken"></param>
        void AddOptAsync(int optId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken);

        /// <summary>
        /// Remove the specified opt from the list of connected opts. If the request completes successfully, the 
        /// Opts collection is modified.
        /// </summary>
        /// <param name="optId"></param>
        /// <param name="requestCompleted"></param>
        /// <param name="userToken"></param>
        void RemoveOptAsync(int optId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken);

        #endregion

    }
}