using MainShell.Recipe.Models.SubstrateParameter;
using System;
using System.Globalization;
using System.Windows.Data;

namespace MainShell.Converter
{
    public class SubstrateHeightMeasureModeToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var mode = value is SubstrateHeightMeasureMode measureMode ? measureMode : SubstrateHeightMeasureMode.StandardTeachPosition;
            var parameterValue = System.Convert.ToInt32(parameter, CultureInfo.InvariantCulture);

            return parameterValue == (int)mode;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is bool isChecked) || !isChecked)
            {
                return Binding.DoNothing;
            }

            var parameterValue = System.Convert.ToInt32(parameter, CultureInfo.InvariantCulture);
            return (SubstrateHeightMeasureMode)parameterValue;
        }
    }
}
