using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wayne.Lib.StateEngine;
using Wayne.Lib.StateEngine.Generic;

namespace SinochemInternetPlusApp.States.ICCardMode
{
    public class WaitForMacData : TimeoutState<FuelingPoint>
    {
        protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
        {
            if (stateEngineEvent.Type.Equals(EventType.DataSigned))
            {
                var @event = stateEngineEvent as GenericEvent<SignedDataEventArgs>;
                if (@event != null && @event.EventArgs != null)
                {
                    @event.Handled = true;
                    Main.SignedData = @event.EventArgs.SignedDataResponse;
                    Main.CurrentEpsTrx.Model.mac = Main.SignedData.MacValue; 
                    transition = new Transition(this, TransitionType.Done);
                }
            }
        }

        protected override void Timeout(ref Transition transition)
        {
            DebugLog("WaitForMacData timed out, fatal error!!!");
            transition = new Transition(this, TransitionType.Timeout);
        }

        protected override int TimeoutInterval =>
            TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.ICCardMode_WaitForMacData, 10);
    }
}