use crate::services::{DataLoaderService, QueryOrchestrator};
use crate::ui::enhanced_tui::EnhancedTuiApp;
use anyhow::Result;
use tracing::info;
pub struct ApplicationOrchestrator {
data_loader: DataLoaderService,
_query_orchestrator: QueryOrchestrator,
}
impl ApplicationOrchestrator {
#[must_use]
pub fn new(case_insensitive: bool, auto_hide_empty: bool) -> Self {
Self {
data_loader: DataLoaderService::new(case_insensitive),
_query_orchestrator: QueryOrchestrator::new(case_insensitive, auto_hide_empty),
}
}
pub fn create_tui_with_file(&self, file_path: &str) -> Result<EnhancedTuiApp> {
info!("Creating TUI with file: {}", file_path);
let load_result = self.data_loader.load_file(file_path)?;
let status_message = load_result.status_message();
let source_path = load_result.source_path.clone();
let table_name = load_result.table_name.clone();
let raw_table_name = load_result.raw_table_name.clone();
let mut app = EnhancedTuiApp::new_with_dataview(load_result.dataview, &source_path)?;
app.set_status_message(status_message);
app.set_sql_query(&table_name, &raw_table_name);
Ok(app)
}
pub fn load_additional_file(&self, app: &mut EnhancedTuiApp, file_path: &str) -> Result<()> {
info!("Loading additional file: {}", file_path);
let load_result = self.data_loader.load_file(file_path)?;
let status_message = load_result.status_message();
let source_path = load_result.source_path.clone();
let table_name = load_result.table_name.clone();
let raw_table_name = load_result.raw_table_name.clone();
app.add_dataview(load_result.dataview, &source_path)?;
app.set_status_message(status_message);
app.set_sql_query(&table_name, &raw_table_name);
Ok(())
}
pub fn execute_query(&mut self, app: &mut EnhancedTuiApp, query: &str) -> Result<()> {
app.execute_query_v2(query)
}
}
pub struct ApplicationOrchestratorBuilder {
case_insensitive: bool,
auto_hide_empty: bool,
}
impl Default for ApplicationOrchestratorBuilder {
fn default() -> Self {
Self::new()
}
}
impl ApplicationOrchestratorBuilder {
#[must_use]
pub fn new() -> Self {
Self {
case_insensitive: false,
auto_hide_empty: false,
}
}
#[must_use]
pub fn with_case_insensitive(mut self, value: bool) -> Self {
self.case_insensitive = value;
self
}
#[must_use]
pub fn with_auto_hide_empty(mut self, value: bool) -> Self {
self.auto_hide_empty = value;
self
}
#[must_use]
pub fn build(self) -> ApplicationOrchestrator {
ApplicationOrchestrator::new(self.case_insensitive, self.auto_hide_empty)
}
}