using SWRIS.Enums;
using SWRIS.Extensions;
using System;
using System.Globalization;
using System.Windows.Data;

namespace SWRIS.Converters
{
    public class RiskLevelToTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var riskLevel = ((RiskLevel)value).GetDescription();
            var texts = riskLevel.ToCharArray();
            if (parameter != null && int.TryParse(parameter.ToString(), out int index) && index >= 0 && index < texts.Length)
            {
                return texts[index];
            }
            return riskLevel;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
