use std::sync::Arc;
use travelagent_core::forge::{ForgeBackend, PrId, PrMetadata, RemoteComment, ReviewThread};
use travelagent_core::vcs::CommitInfo;
use super::RemotePanel;
#[derive(Debug, Default)]
pub struct LocalState {}
pub struct RemoteSessionState {
pub forge: Option<Arc<dyn ForgeBackend>>,
pub pr_id: PrId,
pub forge_host: Option<String>,
pub pr_metadata: Option<PrMetadata>,
pub pr_commits: Vec<CommitInfo>,
pub remote_comments: Vec<RemoteComment>,
pub review_threads: Vec<ReviewThread>,
pub remote_panel: RemotePanel,
pub conversation_scroll: usize,
pub conversation_cursor: usize,
pub replying_to_thread: Option<String>,
pub description_scroll: usize,
pub pr_commits_cursor: usize,
pub review_verdict_cursor: usize,
pub review_body: String,
pub review_body_editing: bool,
pub last_refreshed_at: Option<chrono::DateTime<chrono::Utc>>,
pub rate_limit_remaining: Option<u32>,
pub reaction_picker_target_thread: Option<String>,
}
impl RemoteSessionState {
pub fn new(forge: Option<Arc<dyn ForgeBackend>>, pr_id: PrId) -> Self {
Self {
forge,
pr_id,
forge_host: None,
pr_metadata: None,
pr_commits: Vec::new(),
remote_comments: Vec::new(),
review_threads: Vec::new(),
remote_panel: RemotePanel::Files,
conversation_scroll: 0,
conversation_cursor: 0,
replying_to_thread: None,
description_scroll: 0,
pr_commits_cursor: 0,
review_verdict_cursor: 0,
review_body: String::new(),
review_body_editing: false,
last_refreshed_at: Some(chrono::Utc::now()),
rate_limit_remaining: None,
reaction_picker_target_thread: None,
}
}
}
#[allow(clippy::large_enum_variant)]
pub enum AppMode {
Local(LocalState),
Remote(RemoteSessionState),
}
impl AppMode {
#[allow(dead_code)]
pub fn is_local(&self) -> bool {
matches!(self, Self::Local(_))
}
pub fn is_remote(&self) -> bool {
matches!(self, Self::Remote(_))
}
pub fn remote(&self) -> Option<&RemoteSessionState> {
if let Self::Remote(r) = self {
Some(r)
} else {
None
}
}
pub fn remote_mut(&mut self) -> Option<&mut RemoteSessionState> {
if let Self::Remote(r) = self {
Some(r)
} else {
None
}
}
}