use serde_json::{Map, Value};
use crate::query::Query;
mod geo;
mod nested;
mod object;
mod scalar;
mod sort;
mod string;
pub use geo::{Geo, GeoPoint};
pub use nested::{Nested, NestedProjection};
pub use object::{Binary, Json, Object};
pub use scalar::{Bool, Date, Number};
pub use sort::{Sort, SortOrder};
pub use string::{Keyword, Text, multi_match};
fn single<S>(wrapper: &str, path: &str, value: Value) -> Query<S> {
let mut inner = Map::new();
inner.insert(path.to_string(), value);
let mut outer = Map::new();
outer.insert(wrapper.to_string(), Value::Object(inner));
Query::leaf(Value::Object(outer))
}
fn exists_q<S>(path: &str) -> Query<S> {
let mut inner = Map::new();
inner.insert("field".to_string(), Value::String(path.to_string()));
let mut outer = Map::new();
outer.insert("exists".to_string(), Value::Object(inner));
Query::leaf(Value::Object(outer))
}
fn range_q<S>(path: &str, bounds: Vec<(&str, Value)>) -> Query<S> {
let mut body = Map::new();
for (key, value) in bounds {
body.insert(key.to_string(), value);
}
single("range", path, Value::Object(body))
}
pub(crate) fn match_all_value() -> Value {
let mut outer = Map::new();
outer.insert("match_all".to_string(), Value::Object(Map::new()));
Value::Object(outer)
}
pub mod kind {
#[derive(Debug)]
pub enum Keyword {}
#[derive(Debug)]
pub enum Text {}
#[derive(Debug)]
pub enum Number {}
#[derive(Debug)]
pub enum Date {}
}
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a valid value for a `{K}` field",
label = "unsupported field type",
note = "use a built-in leaf type, or add `#[derive(FlussoValue)]` (with the matching kind) to `{Self}`"
)]
pub trait FlussoValue<K> {}
impl FlussoValue<kind::Keyword> for String {}
impl FlussoValue<kind::Keyword> for &str {}
impl FlussoValue<kind::Text> for String {}
impl FlussoValue<kind::Text> for &str {}
impl FlussoValue<kind::Number> for i8 {}
impl FlussoValue<kind::Number> for i16 {}
impl FlussoValue<kind::Number> for i32 {}
impl FlussoValue<kind::Number> for i64 {}
impl FlussoValue<kind::Number> for f32 {}
impl FlussoValue<kind::Number> for f64 {}
#[cfg(feature = "decimal")]
impl FlussoValue<kind::Number> for crate::Decimal {}
impl FlussoValue<kind::Date> for String {}