using CFX;
using CFX.Production;
using CFX.Structures;
using Sln.Iot.CFX.CFXBusiness;
using Sln.Iot.Serilog;

namespace Sln.Iot.CFX.Event
{
    /// <summary>
    /// 工单完成事件
    /// 带扫码枪的设备Units栏位中的UnitIdentifier必须填写
    /// </summary>
    public class WorkCompletedEvent
    {
        private CFXEventTools cFXEventTools = CFXEventTools.Instance;

        /// <summary>
        /// 数据封装处理
        /// </summary>
        /// <returns></returns>
        public CFXMessage Handle(Guid transactionID, string pirmaryIdentifier, string[] unitIdentifier)
        {
            CFXMessage eve = null;
            try
            {
                eve = new WorkCompleted()
                {
                    TransactionID = transactionID,
                    PrimaryIdentifier = pirmaryIdentifier,
                    Result = WorkResult.Completed,
                    Units = cFXEventTools.UnitPositionTrans(unitIdentifier)
                    //Units = new List<UnitPosition>()
                    //{
                    //    new UnitPosition()
                    //    {
                    //        UnitIdentifier = "PreHeatOven",
                    //        PositionNumber = 1,
                    //        PositionName = "位置1",
                    //        X = 50.0,
                    //        Y = 80.0,
                    //        Rotation = 0.0,
                    //        FlipX = false,
                    //        FlipY = false
                    //    },
                    //    new UnitPosition()
                    //    {
                    //        UnitIdentifier = "PreCureOven",
                    //        PositionNumber = 2,
                    //        PositionName = "位置2",
                    //        X = 50.0,
                    //        Y = 80.0,
                    //        Rotation = 0.0,
                    //        FlipX = false,
                    //        FlipY = false
                    //    },
                    //    new UnitPosition()
                    //    {
                    //        UnitIdentifier = "CureOven",
                    //        PositionNumber = 3,
                    //        PositionName = "位置3",
                    //        X = 50.0,
                    //        Y = 80.0,
                    //        Rotation = 0.0,
                    //        FlipX = false,
                    //        FlipY = false
                    //    },
                    //}

                };
            }
            catch (Exception e)
            {
                SerilogHelper.Instance.Error("终端节点连接事件数据封装异常", e);
            }
            return eve;
        }
    }
}
