using System;
using System.Globalization;
using System.Windows.Data;
using MECF.Framework.Common.Account.Permissions;

namespace MECF.Framework.UI.Client.RecipeEditorLib.Converters
{
    public class ParamValueDisplayConverter : IMultiValueConverter
    {
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            // value[0] must be Param.Value
            // value[1] must be Param.Permission
            // value[2] must be Param.IsHideValue
            // value[3] must be Param.HiddenValueMasking
            if (value is not { Length: 4 }) 
                return value;
            
            if (value[1] is MenuPermissionEnum perm && value[2] is bool isHideValue && value[3] is string masking)
            {
                return perm == MenuPermissionEnum.MP_NONE | isHideValue ? masking : value[0].ToString();
            }
                
            return value[0];
        }

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