namespace EEMSUIClient.Converter;

public class DeviceModelEnumConvert : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value?.ToString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not string s)
            return value;

        if (!Enum.TryParse<DeviceModel>(s, out DeviceModel result))
            return value;


        return result;
    }
}

public class DeviceStatusEnumConvert : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value?.ToString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not string s)
            return value;

        if (!Enum.TryParse(s, out DeviceStatus result))
            return value;


        return result;
    }
}


public class RecipeTypeEnumConvert : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value?.ToString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not string s)
            return value;

        if (!Enum.TryParse(s, out RecipeType result))
            return value;


        return result;
    }
}

