using MainShell.Common;
using System;

namespace MainShell.Vision
{
    /// <summary>
    /// 视觉处理结果
    /// </summary>
    public class VisionProcessResult
    {
        /// <summary>
        /// 是否执行成功
        /// </summary>
        public bool Succeeded { get; set; }

        public VisionFailureCategory FailureCategory { get; set; }

        public VisionErrorCode ErrorCode { get; set; }

        public int? AlarmId { get; set; }

        public MessageKey UserMessageKey { get; set; }

        /// <summary>
        /// 供用户查看的提示信息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 处理失败时的异常对象
        /// </summary>
        public Exception Exception { get; set; }

        /// <summary>
        /// 创建成功结果
        /// </summary>
        public static VisionProcessResult Success()
        {
            return new VisionProcessResult
            {
                Succeeded = true,
                FailureCategory = VisionFailureCategory.None,
                ErrorCode = VisionErrorCode.None,
                AlarmId = null,
                UserMessageKey = MessageKey.None,
            };
        }

        /// <summary>
        /// 创建失败结果
        /// </summary>
        public static VisionProcessResult Failure(
            VisionFailureCategory failureCategory,
            VisionErrorCode errorCode,
            int? alarmId,
            MessageKey userMessageKey,
            string message,
            Exception exception = null)
        {
            return new VisionProcessResult
            {
                Succeeded = false,
                FailureCategory = failureCategory,
                ErrorCode = errorCode,
                AlarmId = alarmId,
                UserMessageKey = userMessageKey,
                Message = message,
                Exception = exception,
            };
        }
    }
}
