using CFX;
using CFX.ResourcePerformance;
using CFX.Structures;
using Sln.Iot.Serilog;

namespace Sln.Iot.CFX.Event
{
    /// <summary>
    /// 设备状态改变事件
    /// </summary>
    public class StationStateChangedEvent
    {
        /// <summary>
        /// 数据封装处理
        /// </summary>
        /// <returns></returns>
        public CFXMessage Handle(ResourceState resourceState)
        {
            CFXMessage eve = null;
            try
            {
                eve = new StationStateChanged()
                {
                    NewState = resourceState,
                    RelatedFault = new Fault()
                    {
                        Cause = FaultCause.MechanicalFailure,
                        Severity = FaultSeverity.Error,
                        FaultCode = "ERROR 3943480",
                        FaultOccurrenceId = Guid.Parse("281fa09f-cbf6-498d-9f27-7ca77cb60399"),
                        Lane = 1,
                        AccessType = AccessType.Local,
                        Description = "Error",
                        OccurredAt = DateTime.Now,
                        TransactionID = Guid.Parse("281fa09f-cbf6-498d-9f27-7ca77cb60399"),
                    }
                };
            }
            catch (Exception e)
            {
                SerilogHelper.Instance.Error("终端节点连接事件数据封装异常", e);
            }
            return eve;
        }
    }
}
