using WCS.Core;
using WCS.WorkEngineering.Worlds.Logs;
using LogInfo = WCS.WorkEngineering.Worlds.Logs.LogInfo;

namespace WCS.WorkEngineering.Extensions
{
    public static class WorldExtension
    {
        /// <summary>
        ///  记录日志
        ///  默认:低级别 已知 不上抛
        /// </summary>
        /// <param name="source">世界</param>
        /// <param name="msg">消息</param>
        public static void Log(this World source, string msg)
        {
            source.Log(new LogInfo { Level = LogLevelEnum.Low, Type = ErrorTypeEnum.Kown, LogUpLoad = LogUpLoadEnum.NotUpLoad, Message = msg });
        }

        /// <summary>
        ///  记录日志
        ///  默认:已知
        ///  上抛根据日志级别决定:低级别不上抛,中高级别上抛WMS
        /// </summary>
        /// <param name="source">世界</param>
        /// <param name="msg">消息</param>
        /// <param name="level">日志级别</param>
        public static void Log(this World source, string msg, LogLevelEnum level)
        {
            LogUpLoadEnum logUpLoad = LogUpLoadEnum.NotUpLoad;
            switch (level)
            {
                case LogLevelEnum.Low:
                    logUpLoad = LogUpLoadEnum.NotUpLoad;
                    break;

                case LogLevelEnum.Mid:
                    logUpLoad = LogUpLoadEnum.UpLoadWMS;
                    break;

                case LogLevelEnum.High:
                    logUpLoad = LogUpLoadEnum.UpLoadWMS;
                    break;

                default:
                    break;
            }
            source.Log(new LogInfo { Level = level, Type = ErrorTypeEnum.Kown, LogUpLoad = logUpLoad, Message = msg });
        }

        /// <summary>
        ///  记录日志
        ///  上抛根据日志级别决定:低级别不上抛,中高级别上抛WMS
        /// </summary>
        /// <param name="source">世界</param>
        /// <param name="msg">消息</param>
        /// <param name="level">日志级别</param>
        /// <param name="errorType">日志类型</param>
        public static void Log(this World source, string msg, LogLevelEnum level, ErrorTypeEnum errorType)
        {
            LogUpLoadEnum logUpLoad = LogUpLoadEnum.NotUpLoad;
            switch (level)
            {
                case LogLevelEnum.Low:
                    logUpLoad = LogUpLoadEnum.NotUpLoad;
                    break;

                case LogLevelEnum.Mid:
                    logUpLoad = LogUpLoadEnum.UpLoadWMS;
                    break;

                case LogLevelEnum.High:
                    logUpLoad = LogUpLoadEnum.UpLoadWMS;
                    break;

                default:
                    break;
            }
            source.Log(new LogInfo { Level = level, Type = errorType, LogUpLoad = logUpLoad, Message = msg });
        }

        /// <summary>
        ///  记录日志
        /// </summary>
        /// <param name="source">世界</param>
        /// <param name="msg">消息</param>
        /// <param name="level">日志级别</param>
        /// <param name="errorType">日志类型</param>
        /// <param name="logUpLoad">日志上抛类型</param>
        public static void Log(this World source, string msg, LogLevelEnum level, ErrorTypeEnum errorType, LogUpLoadEnum logUpLoad)
        {
            source.Log(new LogInfo { Level = level, Type = errorType, LogUpLoad = logUpLoad, Message = msg });
        }
    }
}
