use anyhow::{Context, Result};
use chrono::Duration;
use std::sync::Arc;
use systemprompt_analytics::AnalyticsService;
use systemprompt_database::DbPool;
use systemprompt_identifiers::{SessionId, SessionSource, UserId};
use systemprompt_oauth::services::SessionCreationService;
use systemprompt_traits::{AnalyticsProvider, SessionAnalytics, UserProvider};
use systemprompt_users::UserService;
pub const DEFAULT_CLI_SESSION_HOURS: i64 = 24;
pub async fn create_local_session_row(
db_pool: &DbPool,
user: &UserId,
ttl: Duration,
) -> Result<SessionId> {
let analytics: Arc<dyn AnalyticsProvider> = Arc::new(
AnalyticsService::new(db_pool, None, None)
.context("Failed to construct analytics service")?,
);
let users: Arc<dyn UserProvider> =
Arc::new(UserService::new(db_pool).context("Failed to construct user service")?);
SessionCreationService::new(analytics, users)
.create_authenticated_session_with_ttl(
user,
&SessionAnalytics::default(),
SessionSource::Cli,
ttl,
)
.await
.context("Failed to insert CLI session row")
}