// SPDX-License-Identifier: LicenseRef-Commercial
//
// agor-pro — Commercial plugin for Agents Orchestrator.
// This crate is NOT open-source. It is distributed only via the
// agents-orchestrator/agents-orchestrator private repository.

mod analytics;
mod branch_policy;
mod budget;
mod export;
mod git_context;
mod marketplace;
mod memory;
mod profiles;
mod router;
mod symbols;

use tauri::{
    plugin::{Builder, TauriPlugin},
    Runtime,
};

pub fn init<R: Runtime>() -> TauriPlugin<R> {
    Builder::new("agor-pro")
        .invoke_handler(tauri::generate_handler![
            pro_status,
            analytics::pro_analytics_summary,
            analytics::pro_analytics_daily,
            analytics::pro_analytics_model_breakdown,
            export::pro_export_session,
            export::pro_export_project_summary,
            profiles::pro_list_accounts,
            profiles::pro_get_active_account,
            profiles::pro_set_active_account,
            marketplace::pro_marketplace_fetch_catalog,
            marketplace::pro_marketplace_installed,
            marketplace::pro_marketplace_install,
            marketplace::pro_marketplace_uninstall,
            marketplace::pro_marketplace_check_updates,
            marketplace::pro_marketplace_update,
            budget::pro_budget_set,
            budget::pro_budget_get,
            budget::pro_budget_check,
            budget::pro_budget_log_usage,
            budget::pro_budget_reset,
            budget::pro_budget_list,
            router::pro_router_recommend,
            router::pro_router_set_profile,
            router::pro_router_get_profile,
            router::pro_router_list_profiles,
            memory::pro_memory_add,
            memory::pro_memory_list,
            memory::pro_memory_search,
            memory::pro_memory_update,
            memory::pro_memory_delete,
            memory::pro_memory_inject,
            memory::pro_memory_extract_from_session,
            symbols::pro_symbols_scan,
            symbols::pro_symbols_search,
            symbols::pro_symbols_find_callers,
            symbols::pro_symbols_status,
            git_context::pro_git_context,
            git_context::pro_git_inject,
            git_context::pro_git_branch_info,
            branch_policy::pro_branch_check,
            branch_policy::pro_branch_policy_list,
            branch_policy::pro_branch_policy_add,
            branch_policy::pro_branch_policy_remove,
        ])
        .build()
}

#[tauri::command]
fn pro_status() -> String {
    "active".to_string()
}

/// Open the sessions.db for the current data directory.
fn open_sessions_db() -> Result<rusqlite::Connection, String> {
    let config = agor_core::config::AppConfig::from_env();
    let db_path = config.data_dir.join("sessions.db");
    rusqlite::Connection::open(&db_path)
        .map_err(|e| format!("Failed to open sessions.db: {e}"))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_pro_status() {
        assert_eq!(pro_status(), "active");
    }
}
