use crate::prelude::*;
use once_cell::sync::Lazy;
use std::sync::RwLock;
pub fn current_env() -> EnvId {
CURRENT_ENV
.read()
.expect("current env lock poisoned")
.clone()
}
pub fn set_current_env(env: EnvId) {
*CURRENT_ENV.write().expect("current env lock poisoned") = env;
}
pub fn make_tenant_ctx(tenant: String, team: Option<String>, user: Option<String>) -> TenantCtx {
let env = current_env();
let tenant_id = TenantId(tenant);
let mut ctx = TenantCtx::new(env, tenant_id);
ctx = ctx.with_team(team.map(TeamId));
ctx = ctx.with_user(user.map(UserId));
ctx
}
static CURRENT_ENV: Lazy<RwLock<EnvId>> = Lazy::new(|| RwLock::new(EnvId("dev".to_string())));