use vfile::util::buf::previewer::BufPreviewer;

use crate::chopper::error::Result;
use crate::source::source::Source;

pub type ChopperSourceFactory = dyn SourceFactory<Box<dyn Source>, ()>;

/// for chopper own internal use, T is going to be Box<dyn Source>, but for
/// use cases outside of chopper, it's important to allow custom sources that
/// do not have to deserialize into Row, but some other more appropriate type
pub trait SourceFactory<S, EA>: Send {
    //TODO: maybe this needs to return yes/no/needs-previewer in case you cannot tell if you can
    // open the file or not just based on the filename alone and need to look at contents
    fn can_create_from_format(&self, format: &str) -> bool;
    fn can_create_from_previewer(&self, previewer: &BufPreviewer) -> bool;
    fn create_source(&self, previewer: BufPreviewer, extra_args: EA) -> Result<S>;

    fn box_clone(&self) -> Box<dyn SourceFactory<S, EA>>;
}

impl<S, EA> Clone for Box<dyn SourceFactory<S, EA>> {
    fn clone(&self) -> Box<dyn SourceFactory<S, EA>> {
        self.box_clone()
    }
}
