use crate::rolling::WriteFactory;
use std::fmt::Display;
use std::fs::File;
use std::path::Path;

pub struct Directory<P: AsRef<Path>, S: Display> {
    path: P,
    prefix: S
}

impl<P: AsRef<Path>, S: Display> Directory<P, S> {
    pub fn new(path: P, prefix: S) -> Self {
        Self {
            path,
            prefix
        }
    }
}

impl<P: AsRef<Path>, S: Display> WriteFactory for Directory<P, S> {
    type Writer = File;

    fn new_writer(&self, name: impl Display) -> std::io::Result<Self::Writer> {
        File::open(
            self.path.as_ref().join(
                format!("{}-{}", self.prefix, name)
            )
        )
    }
}