use crate::util::location::Location;

pub trait StreamingTransport: Send {
    /// only checks if schema is supported, the actual location is not checked; this call is cheap
    fn supports_schema(&self, loc: &Location) -> bool;
    /// returned reader should avoid buffering itself; caller will be responsible for buffering;
    /// using timestamp range is optional for transport implementations (some require it)
    fn open(&self, loc: &Location) -> std::io::Result<Box<dyn std::io::Read + Send>>;

    fn box_clone(&self) -> Box<dyn StreamingTransport>;
    fn name(&self) -> &str;
}

impl Clone for Box<dyn StreamingTransport> {
    fn clone(&self) -> Box<dyn StreamingTransport> {
        self.box_clone()
    }
}

impl std::fmt::Debug for dyn StreamingTransport {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(self.name())
    }
}
