using System;
using System.Globalization;
using Xamarin.Forms;
using TINK.Model.User.Account;
namespace TINK.View.Settings
{
///
/// Translates user permissions into visibility state.
/// Used for container which holds a bunch of GUI elemets which migth all/ partly/ none be visible
/// If all childs are invisible frame must be invisible as well. As soon as one child is visible frame must be visible as well.
///
public class BackendPermissionsToVisibleConverter : IValueConverter
{
/// Converts permission value into visible state.
/// Permission value from view model used to derive whether object is visible or not.
/// Boolean value indicating whether object is visible or not.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var enumValue = (Permissions)value;
return enumValue.HasFlag(Permissions.PickCopriServer) | enumValue.HasFlag(Permissions.ManagePolling) | enumValue.HasFlag(Permissions.ManageCopriCacheExpiration);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Permissions.None;
}
}
}