use crate::repository::{auth::AuthRepository, DoqiumClient};
use anyhow::Result;

pub async fn admin_list_users(token: &str) -> Result<Vec<crate::api::AdminUser>> {
    let client = DoqiumClient::new_admin(token)?;
    let repo = AuthRepository::new(&client);
    let users = repo.list_users().await?;
    Ok(users.into_iter().map(crate::api::AdminUser::from).collect())
}

pub async fn admin_delete_user(token: &str, user_id: &str) -> Result<()> {
    let client = DoqiumClient::new_admin(token)?;
    let repo = AuthRepository::new(&client);
    repo.delete_user(user_id).await
}

pub async fn admin_block_user(token: &str, user_id: &str, reason: &str) -> Result<()> {
    let client = DoqiumClient::new_admin(token)?;
    let repo = AuthRepository::new(&client);
    repo.block_user(user_id, reason).await
}

pub async fn admin_unblock_user(token: &str, user_id: &str) -> Result<()> {
    let client = DoqiumClient::new_admin(token)?;
    let repo = AuthRepository::new(&client);
    repo.unblock_user(user_id).await
}

pub async fn admin_logout_user(token: &str, user_id: &str) -> Result<u32> {
    let client = DoqiumClient::new_admin(token)?;
    let repo = AuthRepository::new(&client);
    repo.logout_user(user_id).await
}

pub async fn admin_auth_stats(token: &str) -> Result<serde_json::Value> {
    let client = DoqiumClient::new_admin(token)?;
    let repo = AuthRepository::new(&client);
    repo.get_stats().await
}
