using C4IT.Logging;
using C4IT.MultiLanguage;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using static C4IT.Logging.cLogManager;

namespace FasdDesktopUi.Basics.Converter
{
    public class LanguageDefinitionsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (!(parameter is string techFieldDescriptor))
                    return "N/A";

                string fieldDescription = cMultiLanguageSupport.GetItem(techFieldDescriptor, techFieldDescriptor);

                if (value is object[] valueArray)
                    return string.Format(fieldDescription, valueArray);

                if (value is List<object> valueList)
                    return string.Format(fieldDescription, valueList.ToArray());

                if (value is object valueString)
                    return string.Format(fieldDescription, valueString);

                return fieldDescription;
            }
            catch (Exception E)
            {
                LogException(E);
                LogEntry($"An Error occured while setting the value ({value}) to field: {parameter}");
            }

            return "N/A";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
