#![allow(dead_code)]
#![allow(unused_imports)]
use crate::models::session::{DeviceInfo, Session, SessionRepository};
use anyhow::Result;
use mongodb::bson::oid::ObjectId;

#[derive(Clone)]
pub struct SessionManager {
    repository: SessionRepository,
}

impl SessionManager {
    pub fn new(db: &mongodb::Database) -> Self {
        Self {
            repository: SessionRepository::new(db),
        }
    }

    pub async fn create_session(
        &self,
        user_id: ObjectId,
        device_info: DeviceInfo,
        token_hash: String,
        duration_hours: i64,
    ) -> Result<ObjectId> {
        self.repository
            .create(user_id, device_info, token_hash, duration_hours)
            .await
    }

    pub async fn get_user_sessions(&self, user_id: &ObjectId) -> Result<Vec<Session>> {
        self.repository.find_by_user(user_id).await
    }

    pub async fn revoke_session(&self, session_id: &ObjectId) -> Result<()> {
        self.repository.revoke(session_id).await
    }

    pub async fn revoke_all_user_sessions(&self, user_id: &ObjectId) -> Result<()> {
        self.repository.revoke_all_for_user(user_id).await
    }

    pub async fn cleanup_expired(&self) -> Result<u64> {
        self.repository.cleanup_expired().await
    }
}
