use crate::error::ValidationError;
use crate::validator::ShaclValidationMode;
use crate::validator::engine::{Engine, NativeEngine, SparqlEngine};
use crate::validator::processor::ShaclProcessor;
use sparql_service::RdfData;

// TODO - move to validation::algorithms module
#[derive(Debug)]
pub struct DataValidation {
    data: RdfData,
}

impl DataValidation {
    pub fn new(data: RdfData) -> Self {
        Self { data }
    }
}

impl ShaclProcessor<RdfData> for DataValidation {
    fn store(&self) -> &RdfData {
        &self.data
    }

    fn runner(mode: &ShaclValidationMode) -> Box<dyn Engine<RdfData>> {
        match mode {
            ShaclValidationMode::Native => Box::new(NativeEngine::new()),
            ShaclValidationMode::Sparql => Box::new(SparqlEngine::new()),
        }
    }

    fn prepare_store(&mut self) -> Result<(), ValidationError> {
        self.data.check_store().map_err(ValidationError::from)
    }
}

impl From<RdfData> for DataValidation {
    fn from(value: RdfData) -> Self {
        Self::new(value)
    }
}
