#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
#else
using System.Windows.Data;
#endif
using System;
using System.Globalization;

namespace BindingMemoryLeak
{
    public class TrainingConverter : IValueConverter
    {
        /// <inheritdoc />
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is null) return Binding.DoNothing;

            int? id = null;
            if (value is int intValue)
                id = intValue;

            if (id is null) return Binding.DoNothing;

            var sessionName = id < 0 ? "SESSION_REST" : $"SESSION_{id}";

            var mipmap = parameter != null && !string.IsNullOrEmpty(parameter.ToString()) && parameter.ToString() == "true";

            return LoadImage.GetImageSource("Trainings", $"{sessionName}.png", mipmap);
        }

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