use super::schema::{ServiceStatus, TrxHook};

/// Aggregates info on the current service status, incl. accounts and tags
pub async fn get_service_status(trx: &mut TrxHook<'_>) -> sqlx::Result<ServiceStatus> {
	let active_accounts_count =
		sqlx::query_scalar!("select count(id) from users where id != '00000000-0000-0000-0000-000000000000' and enabled is true")
			.fetch_one(&mut **trx)
			.await?
			.unwrap_or(0);

	let active_tags_count =
		sqlx::query_scalar!("select count(id) from doll_profiles where archived_at is null")
			.fetch_one(&mut **trx)
			.await?
			.unwrap_or(0);

	Ok(ServiceStatus {
		active_accounts_count,
		active_tags_count,
	})
}
