use super::*;
#[derive(Debug, Clone, PartialEq)]
pub struct FunctionCall {
pub(crate) func: Func,
pub(crate) args: Vec<Expr>,
pub(crate) mods: Vec<FuncArgMod>,
pub(crate) filter: Option<Condition>,
}
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct FuncArgMod {
pub distinct: bool,
}
impl FunctionCall {
pub(crate) fn new(func: impl Into<Func>) -> Self {
Self {
func: func.into(),
args: Vec::new(),
mods: Vec::new(),
filter: None,
}
}
pub fn arg<T>(self, arg: T) -> Self
where
T: Into<Expr>,
{
self.arg_with(arg, Default::default())
}
pub(crate) fn arg_with<T>(mut self, arg: T, mod_: FuncArgMod) -> Self
where
T: Into<Expr>,
{
self.args.push(arg.into());
self.mods.push(mod_);
self
}
pub fn args<I>(mut self, args: I) -> Self
where
I: IntoIterator<Item = Expr>,
{
self.args = args.into_iter().collect();
self.mods = vec![Default::default(); self.args.len()];
self
}
pub fn get_func(&self) -> &Func {
&self.func
}
pub fn get_args(&self) -> &[Expr] {
&self.args
}
pub fn get_mods(&self) -> &[FuncArgMod] {
&self.mods
}
pub fn filter(mut self, condition: impl Into<Condition>) -> Self {
self.filter = Some(condition.into());
self
}
pub fn get_filter(&self) -> Option<&Condition> {
self.filter.as_ref()
}
}