using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
using ShellChina_EPS_Project_CarPlatePay_EpsClient_App.MessageEntity.Base;

namespace ShellChina_EPS_Project_CarPlatePay_EpsClient_App
{
    public class ShellChinaEPSClientHandler : IDeviceHandler<byte[], MessageBase>
    {
        public IContext<byte[], MessageBase> EPSClientContext { get; set; }

        private object syncObj = new object();

        public void Init(IContext<byte[], MessageBase> context)
        {
            EPSClientContext = context;
        }

        /// <summary>
        /// called when message received from EPS
        /// </summary>
        /// <param name="context"></param>
        public Task Process(IContext<byte[], MessageBase> context)
        {
            //Message received from EPS
            return Task.CompletedTask;
        }

        //MessageBase will replace with the 8583 message type
        public void WriteAsync(MessageBase request, Func<MessageBase, MessageBase, bool> responseCapture, Action<MessageBase, MessageBase> callback, int timeout)
        {
            lock (syncObj)
            {
               this.EPSClientContext.Outgoing.WriteAsync(request, responseCapture,callback,timeout); 
            }
        }
    }
}