use std::sync::{Arc, Mutex};

use crate::shared::types::Lang;

pub struct Session {
    pub user_id: Option<String>,
    pub lang: Lang,
}

impl Session {
    pub fn new() -> Self {
        Self { user_id: None, lang: Lang::Fr }
    }

    pub fn get_user_id(&self) -> Result<&str, String> {
        self.user_id.as_deref().ok_or_else(|| "No user session. Please log in first.".to_string())
    }
}

pub type SessionState = Arc<Mutex<Session>>;

pub fn create_session() -> SessionState {
    Arc::new(Mutex::new(Session::new()))
}
