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

namespace SWRIS.Converters
{
    public class ResetTypeToBooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null) { return false; }

            if (value is short valueResetType && short.TryParse(parameter.ToString(), out short parameterResetType))
            {
                if (parameterResetType == 1)
                {
                    return valueResetType >= parameterResetType;
                }
                return valueResetType == parameterResetType;
            }
            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
                return 0;

            if (value is bool boolValue && boolValue)
            {
                if (short.TryParse(parameter.ToString(), out short parameterResetType))
                {
                    return parameterResetType;
                }
            }
            return 0;
        }
    }
}
