using System.Collections;
using System.Globalization;
using System.Windows.Data;

namespace BPA.SingleDevice.Converters
{
    public class DictionaryValueMultiConverter: IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length == 2 && values[0] is IDictionary dictionary && values[1] != null)
            {
                var key = int.Parse(values[1].ToString());
                if (dictionary.Contains(key))
                {
                    var result = dictionary[key].ToString();
                    return result;
                }
            }

            return null;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}