using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace EMDServer.Common.Web
{
    public class WebInterface:iEMDConnection
    {
        #region Class variables
        // ----------------------------------------
        public event EventHandler<CommandHandler> cmdReceived;
        // ----------------------------------------
        #endregion

        #region Public methods
        // ----------------------------------------
        /// <summary>
        /// Creates a new instance of the class which is
        /// responsible for the communication over the Web
        /// </summary>
        public WebInterface()
        {
            Debug.WriteLine("WEBINTERFACE - Instantiated!");
        }
        // ----------------------------------------
        #endregion

        #region iEMDConnection Members
        // ----------------------------------------
        /// <summary>
        /// Creates a new connection to the webserver
        /// </summary>
        /// <returns>bool value which indicates whether the connection
        /// to the webserver could be opened</returns>
        public bool openConnection()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Closes the web connection
        /// </summary>
        /// <returns>bool value which indicates whether the connection
        /// could be closed</returns>
        public bool closeConnection()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Sends a command over the web interface
        /// </summary>
        /// <param name="cmd">Command which has to be sent</param>
        public void sendCommand(Command cmd)
        {
            throw new NotImplementedException();
        }
        // ----------------------------------------
        #endregion

        #region Eventhandler
        // ----------------------------------------
        /// <summary>
        /// Issues an event as soon as a new command message
        /// has been arrived
        /// </summary>
        /// TODO: Get event from Wesbserver!!
        private void webServer_msgReceived(object sender, EventArgs e)
        {
            // call maincontroller
            CommandHandler cmdHandler = new CommandHandler(); //{ cmd = webServer.getMessage() };
            OnCommandReceived(cmdHandler);

            Debug.WriteLine("WEBINTERFACE - New message received!");
        }

        public void OnCommandReceived(CommandHandler cmdHandler)
        {
            if (this.cmdReceived != null)
            {
                cmdReceived(this, cmdHandler);
            }
        }
        // ----------------------------------------
        #endregion
    }
}
