use crate::{PartialConfig, StateError};
use fast_down::{ProgressEntry, UrlInfo, WorkerId, reqwest::ReqwestResponseError};
use std::{path::PathBuf, time::Duration};
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum Event {
Prefetch(UrlInfo),
PrefetchError(ReqwestResponseError),
GenPathError(std::io::Error),
StateSaveError(StateError),
BuildClientError(reqwest::Error),
BuildPusherError(std::io::Error),
Allocating(u64),
AllocError(std::io::Error),
RenameFailed(std::io::Error),
Renamed(PathBuf),
Start {
tmp_path: PathBuf,
config_path: PathBuf,
parsed_config: PartialConfig,
},
Resumed {
config_path: PathBuf,
progress: Vec<ProgressEntry>,
size: u64,
},
ResumeError(StateError),
Pulling(WorkerId),
PullError(WorkerId, anyhow::Error),
PullTimeout(WorkerId),
PullProgress(WorkerId, ProgressEntry),
Pushing(WorkerId, ProgressEntry),
PushError(WorkerId, ProgressEntry, anyhow::Error),
PushProgress(ProgressEntry),
Progress(ProgressSample),
Flushing,
FlushError(anyhow::Error),
Finished(WorkerId),
Terminated(TerminationReason),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TerminationReason {
Completed,
Cancelled,
Incomplete,
Failed,
}
#[derive(Debug, Clone)]
pub struct ProgressSample {
pub progress: Vec<ProgressEntry>,
pub bps: u64,
pub avg_bps: u64,
pub downloaded: u64,
pub percent: f64,
pub total: u64,
pub elapsed: Duration,
pub eta: Option<Duration>,
}