use pandora_lib_assembler::assembler::{
    assemble_whole, spades::SpadesConfig, wtdbg2::Wtdbg2Config, AssembleConfig,
};

#[derive(Debug, Clone)]
pub struct AssemblerConfig {
    pub result_dir: String,
    pub scan_dir_name: String,
    pub output_dir_name: String,
    pub dict_file: String,
}

impl Default for AssemblerConfig {
    fn default() -> Self {
        Self {
            result_dir: "/data/longreads_basic_pipe".to_string(),
            scan_dir_name: "scan".to_string(),
            output_dir_name: "assemblies".to_string(),
            dict_file: "/data/ref/hs1/chm13v2.0.dict".to_string(),
        }
    }
}

#[derive(Debug)]
pub struct Assembler {
    pub id: String,
    pub time_point: String,
    pub config: AssemblerConfig,
}

impl Assembler {
    pub fn new(
        id: String,
        time_point: String,
        config: AssemblerConfig,
    ) -> Self {
        Assembler {
            id,
            time_point,
            config,
        }
    }

    pub fn run(&self) -> anyhow::Result<()> {
        let case_dir = format!("{}/{}/{}", self.config.result_dir, self.id, self.time_point);
        let scan_reads_dir = format!("{case_dir}/{}/reads", self.config.scan_dir_name);
        let output_dir = format!("{case_dir}/assemblies");

        assemble_whole(
            &scan_reads_dir,
            &[
                AssembleConfig::Spades(SpadesConfig::new(&output_dir)),
                AssembleConfig::Wtdbg2(Wtdbg2Config::new(&output_dir)),
            ],
            1,
        )
    }
}
