//! `pic collections ls --group <g>` — read-only view of a group's §11.6 shared
//! KV collections. Group-only (shared collections are owned by groups);
//! authoring is declarative via the `[group]` manifest `collections = [...]`.
//! Scripts read/write them with `kv::shared_collection("name")`.

use anyhow::Result;

use crate::client::Client;
use crate::config;
use crate::output::{OutputMode, Table};

pub async fn ls(group: &str, mode: OutputMode) -> Result<()> {
    let creds = config::resolve()?;
    let client = Client::from_creds(&creds)?;
    let items = client.collections_list(group).await?;

    let mut table = Table::new(["name", "kind"]);
    for c in &items {
        table.row([c.name.clone(), c.kind.clone()]);
    }
    table.print(mode);
    Ok(())
}
