use std::sync::Arc;
use crate::ids::VariableId;
use crate::intervention::Intervention;
use super::error::QueryError;
#[derive(Clone, Debug, PartialEq)]
pub struct CounterfactualQuery {
pub outcomes: Arc<[VariableId]>,
pub interventions: Arc<[Intervention]>,
pub allow_nested: bool,
}
impl CounterfactualQuery {
#[must_use]
pub fn new(outcome: VariableId, interventions: impl Into<Arc<[Intervention]>>) -> Self {
Self {
outcomes: Arc::from([outcome]),
interventions: interventions.into(),
allow_nested: false,
}
}
#[must_use]
pub const fn with_nested(mut self, allow_nested: bool) -> Self {
self.allow_nested = allow_nested;
self
}
pub fn validate(&self) -> Result<(), QueryError> {
if self.outcomes.is_empty() {
return Err(QueryError::EmptyCounterfactualOutcomes);
}
for iv in self.interventions.iter() {
iv.validate().map_err(|e| QueryError::InvalidIntervention(e.to_string()))?;
}
Ok(())
}
}