namespace Firebase.Database.Query
{
using System;
using System.Globalization;
///
/// Represents a firebase filtering query, e.g. "?LimitToLast=10".
///
public class FilterQuery : ParameterQuery
{
private readonly Func valueFactory;
private readonly Func doubleValueFactory;
private readonly Func boolValueFactory;
///
/// 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)
{
this.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)
{
this.boolValueFactory = valueFactory;
}
///
/// The build url parameter.
///
/// The child.
/// Url parameter part of the resulting path.
protected override string BuildUrlParameter(FirebaseQuery child)
{
if (this.valueFactory != null)
{
if(this.valueFactory() == null)
{
return $"null";
}
return $"\"{this.valueFactory()}\"";
}
else if (this.doubleValueFactory != null)
{
return this.doubleValueFactory().ToString(CultureInfo.InvariantCulture);
}
else if (this.boolValueFactory != null)
{
return $"{this.boolValueFactory().ToString().ToLower()}";
}
return string.Empty;
}
}
}