using System;
using System.Globalization;
namespace Firebase.Database.Query
{
///
/// Represents a firebase filtering query, e.g. "?LimitToLast=10".
///
public class FilterQuery : ParameterQuery
{
private readonly Func boolValueFactory;
private readonly Func doubleValueFactory;
private readonly Func valueFactory;
///
/// Initializes a new instance of the class.
///
/// The parent.
/// The filter.
/// The value for filter.
/// The owning client.
public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory,
FirebaseClient client)
: base(parent, filterFactory, client)
{
this.valueFactory = valueFactory;
}
///
/// Initializes a new instance of the class.
///
/// The parent.
/// The filter.
/// The value for filter.
/// The owning client.
public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory,
FirebaseClient client)
: base(parent, filterFactory, client)
{
doubleValueFactory = valueFactory;
}
///
/// Initializes a new instance of the class.
///
/// The parent.
/// The filter.
/// The value for filter.
/// The owning client.
public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory,
FirebaseClient client)
: base(parent, filterFactory, client)
{
boolValueFactory = valueFactory;
}
///
/// The build url parameter.
///
/// The child.
/// Url parameter part of the resulting path.
protected override string BuildUrlParameter(FirebaseQuery child)
{
if (valueFactory != null)
{
if (valueFactory() == null) return "null";
return $"\"{valueFactory()}\"";
}
if (doubleValueFactory != null)
return doubleValueFactory().ToString(CultureInfo.InvariantCulture);
if (boolValueFactory != null) return $"{boolValueFactory().ToString().ToLower()}";
return string.Empty;
}
}
}