use std::path::Path;

use super::Importer;
use crate::{
    StepID, importer::GenericImportConfiguration, progress::ProgressReporter,
    workflow::StatusSender,
};
use facet::Facet;
use graphannis::update::GraphUpdate;
use serde::Serialize;
use serde_derive::Deserialize;

/// A special importer that imports nothing.
#[derive(Facet, Default, Deserialize, Serialize, Clone, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct CreateEmptyCorpus {}

impl Importer for CreateEmptyCorpus {
    fn import_corpus(
        &self,
        _path: &Path,
        step_id: StepID,
        _config: GenericImportConfiguration,
        tx: Option<StatusSender>,
    ) -> Result<GraphUpdate, Box<dyn std::error::Error>> {
        let progress_reporter = ProgressReporter::new(tx, step_id, 1)?;
        let graph_update = GraphUpdate::default();
        progress_reporter.worked(1)?;
        Ok(graph_update)
    }

    fn default_file_extensions(&self) -> &[&str] {
        &[]
    }
}

#[cfg(test)]
mod tests {
    use insta::assert_snapshot;

    use crate::importer::none::CreateEmptyCorpus;

    #[test]
    fn serialize() {
        let module = CreateEmptyCorpus::default();
        let serialization = toml::to_string(&module);
        assert!(
            serialization.is_ok(),
            "Serialization failed: {:?}",
            serialization.err()
        );
        assert_snapshot!(serialization.unwrap());
    }
}
