using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace FLY.Thick.Base.UI
{
    public interface IErrNoTranslator
    {
        /// <summary>
        /// errNoKey 查表 获取 文字
        /// </summary>
        /// <param name="errNoKey"></param>
        /// <returns></returns>
        string ToDescription(string errNoKey);
    }
    public class ErrNoTranslator : IErrNoTranslator
    {
        ResourceDictionary rd_errnos = null;
        public virtual string DictKey => "";
        public ErrNoTranslator() 
        {
            //提前全部
            string resourceName = $"dict{DictKey}.StringResource.ERRNO";

            rd_errnos = (ResourceDictionary)Application.Current.TryFindResource(resourceName);
            if (rd_errnos == null)
            {
                throw new Exception($"can't find out ResourceDictionary x:Key = \"{resourceName}\"");
            }
        }

        public virtual string ToDescription(string errNoKey)
        {
            if (rd_errnos != null && !string.IsNullOrEmpty(errNoKey))
            {
                string resourceName = $"str{DictKey}.ERRNO.{errNoKey}";

                if (rd_errnos.Contains(resourceName))
                {
                    return (string)rd_errnos[resourceName];
                }
            }

            return null;
            
        }
    }
}
