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

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

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

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

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