use crate::repository::{data::DataRepository, DoqiumClient};
use anyhow::Result;

pub async fn list_workspaces(token: &str) -> Result<Vec<crate::api::Workspace>> {
    let client = DoqiumClient::new(token)?;
    let repo = DataRepository::new(&client);
    let workspaces = repo.list_workspaces().await?;
    Ok(workspaces.into_iter().map(|w| w.into()).collect())
}

pub async fn create_workspace(token: &str, name: &str) -> Result<String> {
    let client = DoqiumClient::new(token)?;
    let repo = DataRepository::new(&client);
    repo.create_workspace(name).await
}

pub async fn update_workspace(token: &str, workspace_id: &str, name: &str) -> Result<()> {
    let client = DoqiumClient::new(token)?;
    let repo = DataRepository::new(&client);
    repo.update_workspace(workspace_id, name).await?;
    Ok(())
}

pub async fn delete_workspace(token: &str, workspace_id: &str) -> Result<()> {
    let client = DoqiumClient::new(token)?;
    let repo = DataRepository::new(&client);
    repo.delete_workspace(workspace_id).await
}
