using System.ComponentModel;
using System.Reflection;

namespace SlnMesnac.Model.dto.taskType
{
    /// <summary>
    /// 任务类型
    /// </summary>
    public static class StaticTaskType
    {
        /// <summary>
        /// 3#车间补四宫格空箱任务
        /// </summary>
        [Description("3#车间补四宫格空箱任务")]
        public const int SupplyEmptyPalletTask = 1;

        /// <summary>
        /// 3#车间从下料点到1-16机台送料任务
        /// </summary>
        [Description("3#车间从下料点到1-16机台送料任务")]
        public const int TransferMaterialBoxTask = 3;

        /// <summary>
        /// 1-12号机台之间空料箱移库任务
        /// </summary>
        [Description("1-12号机台之间空料箱移库任务")]
        public const int MoveLocationTask = 10;

        /// <summary>
        /// 3#接驳位到2#计量室接驳位的送料任务
        /// </summary>
        [Description("3#接驳位到2#计量室接驳位的送料任务")]
        public const int TransferMaterialMetrologyRoomBoxTask = 4;

        /// <summary>
        /// 3#车间从2#接驳位补充小托盘任务
        /// </summary>
        [Description("3#车间补充小托盘任务")]
        public const int SupplySmallPalletTask = 2;

        /// <summary>
        /// 3#车间从色粉存放点补充小托盘任务
        /// </summary>
        [Description("3#车间补充小托盘任务")]
        public const int SupplySmallPalletFromTonerTask = 6;

        /// <summary>
        /// 2#接驳位色粉派送至色粉存放点
        /// </summary>
        [Description("2#接驳位色粉派送至色粉存放点")]
        public const int DeliverTonerTask = 5;

        /// <summary>
        /// 不使用---色粉存放点空托盘派送至2#接驳位
        /// </summary>
        [Description("色粉存放点空托盘派送至2#接驳位")]
        public const int EmptyReturnFromTonerTask = 7;

        /// <summary>
        /// 四宫格前往异常库位任务处理
        /// </summary>
        [Description("四宫格前往异常库位任务处理")]
        public const int ExceptionTask = 8;

        // 定义一个静态方法来获取字段的 Description 特性值
        public static string GetDescription(int value)
        {
            var fields = typeof(StaticTaskType).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
            foreach (var field in fields)
            {
                if (field.FieldType == typeof(int) && (int)field.GetValue(null) == value)
                {
                    DescriptionAttribute[] attributes = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (attributes.Length > 0)
                    {
                        return attributes[0].Description;
                    }
                }
            }
            return value.ToString();
        }
    }
}