use vfile::transport::output::output_transport::OutputTransport;

use crate::chopper::error::Result;
use crate::output::factory::OutputFactory;
use crate::sink::csv_output_config::CSVOutputConfig;
use crate::util::dc_factory::DCFactory;

pub struct OutputFactoryBuilder {
    dc_factory: Option<DCFactory>,
    csv_output_config: Option<CSVOutputConfig>,
    user_output_transports: Option<Vec<Box<dyn OutputTransport>>>,
}

impl OutputFactoryBuilder {
    pub fn new() -> OutputFactoryBuilder {
        OutputFactoryBuilder {
            dc_factory: None,
            csv_output_config: None,
            user_output_transports: None,
        }
    }

    pub fn with_dc_factory(mut self, dc_factory: Option<DCFactory>) -> Self {
        self.dc_factory = dc_factory;
        self
    }

    pub fn with_csv_output_config(mut self, csv_output_config: CSVOutputConfig) -> Self {
        self.csv_output_config = Some(csv_output_config);
        self
    }

    pub fn with_user_output_transports(
        mut self,
        user_output_transports: Option<Vec<Box<dyn OutputTransport>>>,
    ) -> Self {
        self.user_output_transports = user_output_transports;
        self
    }

    pub fn build(self) -> Result<OutputFactory> {
        Ok(OutputFactory::new(
            self.dc_factory,
            self.csv_output_config,
            self.user_output_transports,
        ))
    }
}
