using System;

using Rowa.Lib.Log;

namespace StorageSystemSimulator
{
    public delegate void WwiMessageEventHandler(object sender, string message, bool isIncommingMessage);

    class WwiLogger : IWwi
    {
        public event WwiMessageEventHandler WwiMessage;

        public WwiLogger()
        {
        }

        ~WwiLogger()
        {
            this.Dispose( false );
        }

        public void LogMessage(byte[] message, bool isIncommingMessage = true)
        {
            if (this.WwiMessage != null)
            {
                string tmp = System.Text.Encoding.UTF8.GetString(message);
                this.WwiMessage(this, tmp, isIncommingMessage);
            }
        }

        public void LogMessage(string message, bool isIncommingMessage = true)
        {
            if (this.WwiMessage != null)
            {
                this.WwiMessage(this, message, isIncommingMessage);
            }
        }

        public void LogMessage(byte[] message, int index, int length, bool isIncommingMessage = true)
        {
            if (this.WwiMessage != null)
            {
                string tmp = System.Text.Encoding.UTF8.GetString(message);
                this.WwiMessage(this, tmp, isIncommingMessage);
            }
        }

        public void Dispose()
        {
            this.Dispose( true );

            GC.SuppressFinalize( this );
        }

        protected virtual void Dispose( bool disposing )
        {
        }
    }
}
