using DbCommon.Enties.DbModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbCommon.Function
{
    public class Tools
    {
        public static string PosArrayToString(string[] posArr)
        {
            if (posArr == null
                || posArr.Length == 0)
            {
                return string.Empty;
            }

            StringBuilder s = new StringBuilder();
            for (int i = 0; i < posArr.Length; i++)
            {
                s.Append(posArr[i].ToString());
                if (i < (posArr.Length - 1))
                {
                    s.Append(",");
                }
            }
            return s.ToString();
        }

        public static string[] StringToPosArray(string posArrString)
        {
            if (string.IsNullOrEmpty(posArrString)) return null;
            if (!posArrString.Contains(","))
            {
                return new string[] { posArrString };
            }

            try
            {
                return posArrString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }
            catch
            {
                return null;
            }
        }

        public static string PosArrayToString(string[] posArr, string str)
        {
            if (posArr == null
                || posArr.Length == 0)
            {
                return string.Empty;
            }

            StringBuilder s = new StringBuilder();
            for (int i = 0; i < posArr.Length; i++)
            {
                s.Append(posArr[i].ToString());
                if (i < (posArr.Length - 1))
                {
                    s.Append(str);
                }
            }
            return s.ToString();
        }


        public static LocationStatus ParseStatus(string status)
        {
            if (string.IsNullOrEmpty(status)) return LocationStatus.None;

            int tempValue;
            if (int.TryParse(status, out tempValue))
            {
                return (LocationStatus)tempValue;
            }
            return LocationStatus.None;
        }

        public static EnumMaterialType ParseMaterial(string material)
        {
            if (string.IsNullOrEmpty(material)) return EnumMaterialType.None;

            int tempValue;
            if (int.TryParse(material, out tempValue))
            {
                return (EnumMaterialType)tempValue;
            }
            return EnumMaterialType.None;
        }

        public static string GetStatusString(LocationStatus status)
        {
            string statusStr = null;
            switch (status)
            {
                case LocationStatus.None:
                    statusStr = "未知";
                    break;
                case LocationStatus.Filled:
                    statusStr = "满";
                    break;
                case LocationStatus.Empty:
                    statusStr = "空";
                    break;
                case LocationStatus.Locked:
                    statusStr = "锁定";
                    break;
                default:
                    statusStr = "未知";
                    break;
            }
            return statusStr;
        }

        public static string GetTaskStatusString(EnumTaskStatus taskStatus)
        {
            string statusStr = null;
            switch (taskStatus)
            {
                case EnumTaskStatus.Called:
                    statusStr = "叫料";
                    break;
                case EnumTaskStatus.Created:
                    statusStr = "已创建";
                    break;
                case EnumTaskStatus.Started:
                    statusStr = "已开始";
                    break;
                case EnumTaskStatus.Finished:
                    statusStr = "已完成";
                    break;
                case EnumTaskStatus.TaskManualDeleted:
                    statusStr = "任务手动删除";
                    break;
                case EnumTaskStatus.TaskAddException:
                    statusStr = "任务添加异常";
                    break;
                case EnumTaskStatus.Exception:
                    statusStr = "任务异常";
                    break;
                default:
                    break;
            }
            return statusStr;
        }
    }
}
