use anyhow::Result;
use log::*;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;

use crate::compression_engine::CompressionEngine;

#[derive(Debug, Eq, PartialEq, Clone, Default)]
pub struct CompressionEngineNone {}

impl CompressionEngineNone {
    pub fn new() -> CompressionEngineNone {
        CompressionEngineNone {}
    }
}

impl CompressionEngine for CompressionEngineNone {
    fn is_supported(&self) -> bool {
        true
    }

    fn get_status_info(&self) -> (String, String, String) {
        ("<INTERNAL>".to_string(), "".to_string(), "".to_string())
    }

    fn open(&self, file_path: PathBuf) -> Result<Box<dyn Read + Send>> {
        debug!("COMPRESSION: Opening {:?} using {:?}", file_path, *self);
        Ok(Box::new(File::open(file_path)?))
    }

    fn create(&self, file_path: PathBuf) -> Result<Box<dyn Write>> {
        debug!("COMPRESSION: Writing to {:?} using {:?}", file_path, *self);
        Ok(Box::new(File::create(file_path)?))
    }

    fn clone_box(&self) -> Box<dyn CompressionEngine> {
        Box::new(self.clone())
    }
}
