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

namespace UIShare.Converters
{
    public class ParameterValueToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is IEnumerable enumerable && !(value is string))
            {
                var elements = enumerable.Cast<object>().Select(item => item?.ToString() ?? "null");
                return $"[{string.Join(", ", elements)}]";
            }
            else if(value != null)
            {
                return value.ToString()!;
            }
            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                return value.ToString()!;
            }
            return "";
        }
    }
}
