using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project.StateMachine
{
    public partial class StateMachine
    {
        public class StateMachineMessageEventArgs : EventArgs
        {
            public string Header { get; set; }
            public string Message { get; set; }
            public StateMachineMessageEventArgs(string header_, string message_)
            {
                this.Message = message_;
                this.Header = header_;
            }
        }
        public event EventHandler<StateMachineMessageEventArgs> Message;
        void RaiseMessage(string header, string msg)
        {
            if (Message != null)
            {
                try
                {
                    // 비동기로 이벤트 발생 (블로킹 방지)
                    var handler = Message;
                    if (handler != null)
                    {
                        var args = new StateMachineMessageEventArgs(header, msg);
                        System.Threading.ThreadPool.QueueUserWorkItem(_ => 
                        {
                            try
                            {
                                handler(this, args);
                            }
                            catch { /* 이벤트 핸들러 예외 무시 */ }
                        });
                    }
                }
                catch { /* 예외 무시 */ }
            }
        }

        public class StepChangeEventArgs : EventArgs
        {
            public eSMStep Old { get; set; }
            public eSMStep New { get; set; }
            public StepChangeEventArgs(eSMStep old_,eSMStep new_)
            {
                this.Old = old_;
                this.New = new_;
            }
        }
        public class RunningEventArgs : EventArgs {
            public Boolean isFirst { get; set; }
            public eSMStep Step { get; set; }
            public TimeSpan StepTime { get; set; }
            public object Data { get; set; }
            public RunningEventArgs( eSMStep step_, Boolean isfirst_,TimeSpan steptime_,object data = null)
            {
                this.isFirst = isfirst_;
                this.Step = step_;
                StepTime = steptime_;
                this.Data = data;
            }
        }
        public event EventHandler<StepChangeEventArgs> StepChanged;
        public event EventHandler SPS;
        public event EventHandler<RunningEventArgs> Running;
    }
    

}
