use anyhow::Result;
use tokio::sync::mpsc;
use super::session::SessionId;
use super::types::StagingMode;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OnboardingStatus {
Searching,
Holding {
local_g2: usize,
local_g3: usize,
remote_g2: usize,
remote_g3: usize,
pending_g4: usize,
loaded_g4: usize,
failed_g4: usize,
},
Preparing {
matched: usize,
staging_local: usize,
staging_remote: usize,
},
Prepared { local_g2: usize, remote_g2: usize },
Staging {
matched: usize,
staging_local: usize,
staging_remote: usize,
pulling: usize,
},
Complete { matched_blocks: usize },
}
#[derive(Debug)]
pub(crate) enum SessionControl {
Prepare,
Pull,
Cancel,
Shutdown,
}
#[derive(Debug)]
pub struct SessionHandle {
session_id: SessionId,
mode: StagingMode,
control_tx: mpsc::Sender<SessionControl>,
}
impl SessionHandle {
pub(crate) fn new(
session_id: SessionId,
mode: StagingMode,
control_tx: mpsc::Sender<SessionControl>,
) -> Self {
Self {
session_id,
mode,
control_tx,
}
}
pub fn session_id(&self) -> SessionId {
self.session_id
}
pub fn mode(&self) -> StagingMode {
self.mode
}
pub async fn prepare(&self) -> Result<()> {
self.control_tx
.send(SessionControl::Prepare)
.await
.map_err(|_| anyhow::anyhow!("session task has exited"))
}
pub async fn pull(&self) -> Result<()> {
self.control_tx
.send(SessionControl::Pull)
.await
.map_err(|_| anyhow::anyhow!("session task has exited"))
}
pub async fn cancel(&self) -> Result<()> {
self.control_tx
.send(SessionControl::Cancel)
.await
.map_err(|_| anyhow::anyhow!("session task has exited"))
}
#[expect(dead_code)]
pub(crate) async fn shutdown(&self) -> Result<()> {
self.control_tx
.send(SessionControl::Shutdown)
.await
.map_err(|_| anyhow::anyhow!("session task has exited"))
}
}