use std::collections::HashMap;
use leptos::prelude::*;
use orbital_data::DataValue;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum AggregationFn {
#[default]
Sum,
Avg,
Min,
Max,
Count,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AggregationRule {
pub field: String,
pub func: AggregationFn,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct AggregationModel {
pub rules: Vec<AggregationRule>,
}
impl AggregationModel {
pub fn new(rules: Vec<AggregationRule>) -> Self {
Self { rules }
}
pub fn is_active(&self) -> bool {
!self.rules.is_empty()
}
pub fn rule_for_field(&self, field: &str) -> Option<AggregationFn> {
self.rules.iter().find(|r| r.field == field).map(|r| r.func)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum AggregationPosition {
#[default]
Footer,
GroupInline,
}
pub type AggregationSignal = Signal<AggregationModel>;
pub type GroupAggregates = HashMap<String, DataValue>;