using System;
using System.Threading;
using MECF.Framework.Simulator.Core.Driver;

namespace CyberX8_Simulator.Devices
{
    class AdTecMatchMock : SerialPortDeviceSimulator
    {
        private const string EOF = "\r";
        private const char MSG_DELIMITER = '\r';
        private const string MOCKUP_PORT = "COM52";

        public AdTecMatchMock() : base(MOCKUP_PORT, -1, EOF, MSG_DELIMITER)
        {
        }

        protected override void ProcessUnsplitMessage(string message)
        {
            if (string.IsNullOrEmpty(message))
                throw new ArgumentException("Hardware command message is invalid");

            message = message.TrimEnd('\r');

            string[] strs = message.Split(MSG_DELIMITER);

            string sRes = string.Empty;

            if (message.Contains("$APRR"))
            {
                sRes = "$APRR10E1D5";
            }
            else
            {
                sRes = "S34000C0000000000000080020015A273B00700700400005C095210";
            }

            Thread.Sleep(2 * 1000);
            OnWriteMessage(sRes + "\r");
        }
    }
}