using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace Minint.ViewModels;

/// <summary>
/// Static IValueConverter instances for binding RadioButton.IsChecked to ToolType.
/// These are one-way (read-only) — the RadioButton Command sets the actual value.
/// </summary>
public static class ToolTypeConverters
{
    public static readonly IValueConverter IsBrush = new ToolTypeConverter(ToolType.Brush);
    public static readonly IValueConverter IsEraser = new ToolTypeConverter(ToolType.Eraser);
    public static readonly IValueConverter IsFill = new ToolTypeConverter(ToolType.Fill);
    public static readonly IValueConverter IsSelect = new ToolTypeConverter(ToolType.Select);

    private sealed class ToolTypeConverter(ToolType target) : IValueConverter
    {
        public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
            => value is ToolType t && t == target;

        public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
            => target;
    }
}
