// 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 export;
mod marketplace;
mod profiles;

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,
        ])
        .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");
    }
}
