using MainShell.Common;
using System;

namespace MainShell.Vision
{
    /// <summary>
    /// 带返回数据的视觉处理结果
    /// </summary>
    /// <typeparam name="TData">视觉处理返回的数据类型</typeparam>
    public class VisionProcessResult<TData> : VisionProcessResult
    {
        /// <summary>
        /// 返回的数据
        /// </summary>
        public TData Data { get; set; }

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

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