use crate::sdk::{
events::FileEvent,
storage::files::{ExternalFile, FileMutationEvent},
};
use indexmap::IndexSet;
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct FileSet(pub IndexSet<ExternalFile>);
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct FileTransfersSet {
pub uploads: FileSet,
pub downloads: FileSet,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum TransferOperation {
Upload,
Download,
Delete,
Move(ExternalFile),
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct FileOperation(pub ExternalFile, pub TransferOperation);
impl From<&FileMutationEvent> for FileOperation {
fn from(value: &FileMutationEvent) -> Self {
match value {
FileMutationEvent::Create { event, .. } => event.into(),
FileMutationEvent::Move(event) => event.into(),
FileMutationEvent::Delete(event) => event.into(),
}
}
}
impl From<&FileEvent> for FileOperation {
fn from(value: &FileEvent) -> Self {
match value {
FileEvent::CreateFile(owner, file_name) => FileOperation(
ExternalFile::new(*owner, *file_name),
TransferOperation::Upload,
),
FileEvent::DeleteFile(owner, file_name) => FileOperation(
ExternalFile::new(*owner, *file_name),
TransferOperation::Delete,
),
FileEvent::MoveFile { name, from, dest } => FileOperation(
ExternalFile::new(*from, *name),
TransferOperation::Move(ExternalFile::new(*dest, *name)),
),
_ => panic!("attempt to convert noop file event"),
}
}
}