use prost::Message as PbMessage;
use sift_error::prelude::*;
use sift_pbfs::BackupsDecoder;
use std::{fs::File, io::BufReader, path::Path};
mod async_manager;
pub(crate) use async_manager::{AsyncBackupsManager, BackupIngestTask};
pub(crate) mod file_writer;
mod policy;
pub use policy::{DiskBackupPolicy, RollingFilePolicy};
pub(crate) fn decode_backup<P, M>(path: P) -> Result<BackupsDecoder<M, BufReader<File>>>
where
P: AsRef<Path>,
M: PbMessage + Default + 'static,
{
File::open(path.as_ref())
.map(BufReader::new)
.map(BackupsDecoder::new)
.map_err(|e| Error::new(ErrorKind::IoError, e))
.context("failed to open backup")
.help("contact Sift")
}