using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Edge.Core.Processor.Communicator
{
    public interface ICommunicator<TRaw, TMessage> : IDisposable
    {
        event EventHandler OnConnected;
        event EventHandler OnDisconnected;

        /// <summary>
        /// fired on error bytes cut(at message cutter) or message parse (at Parser.Deserialize).
        /// </summary>
        event EventHandler<CommunicatorErrorMessageReadEventArg> OnErrorMessageRead;
        /// <summary>
        /// fired on data (with message form, have NOT parsed into type TRaw) is about send to the device, can cancel the writing operation.
        /// </summary>
        event EventHandler<CommunicatorEventArg<TRaw, TMessage>> OnRawDataWriting;

        /// <summary>
        /// fired on raw data received from the device, and not deserialized to message yet.
        /// </summary>
        event EventHandler<CommunicatorEventArg<TRaw, TMessage>> OnDataReceived;

        /// <summary>
        /// msg from underlying(no matter SerialPort or tcp), it always need to be cut into a full msg, and then
        /// feed in to parser to parse to an Object for handler use.
        /// </summary>
        //IMessageCutter<T> MessageCutter { get; }
        Task<bool> Start();
        bool Write(TMessage message);
        bool Write(TMessage message, object extraControlParameter);

        /// <summary>
        /// Used to get or set the abstract description for this comm.
        /// </summary>
        string Identity { get; set; }

    }
}
