using System.Globalization;
using Avalonia.Data.Converters;
using JdeScoping.ConfigManager.Models;
namespace JdeScoping.ConfigManager.Converters;
///
/// Converts a ConnectionProvider value to visibility (bool) based on whether it matches the target provider.
///
public class ProviderToVisibilityConverter : IValueConverter
{
///
/// Converter instance for SqlServer provider visibility.
///
public static readonly ProviderToVisibilityConverter SqlServer = new(ConnectionProvider.SqlServer);
///
/// Converter instance for Oracle provider visibility.
///
public static readonly ProviderToVisibilityConverter Oracle = new(ConnectionProvider.Oracle);
///
/// Converter instance for Generic provider visibility.
///
public static readonly ProviderToVisibilityConverter Generic = new(ConnectionProvider.Generic);
private readonly ConnectionProvider _targetProvider;
///
/// Initializes a new instance of the class.
///
/// The provider to match for visibility.
public ProviderToVisibilityConverter(ConnectionProvider targetProvider)
{
_targetProvider = targetProvider;
}
///
/// Converts a ConnectionProvider to a boolean indicating visibility.
///
/// The ConnectionProvider value to convert.
/// The target type (bool).
/// Unused converter parameter.
/// The culture for conversion.
/// True if the value matches the target provider; otherwise, false.
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is ConnectionProvider provider)
{
return provider == _targetProvider;
}
return false;
}
///
/// Not implemented - this is a one-way converter.
///
/// The value to convert back.
/// The target type.
/// Unused converter parameter.
/// The culture for conversion.
/// This converter does not support reverse conversion.
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}