//! `pic suppress ls --app <a>` / `--group <g>` — read-only view of an owner's
//! §11 tail opt-outs: the inherited group templates it declines. An app declines
//! for itself; a group declines for its whole subtree (§11 tail M1). Authoring
//! is declarative via the `[suppress]` block (`triggers = [...]` handler script
//! names, `routes = [...]` paths).

use anyhow::Result;

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

pub async fn ls(app: Option<&str>, group: Option<&str>, mode: OutputMode) -> Result<()> {
    let creds = config::resolve()?;
    let client = Client::from_creds(&creds)?;
    let items = match crate::cmds::require_one_owner(app, group)? {
        crate::cmds::OwnerRef::App(a) => client.suppressions_list(a).await?,
        crate::cmds::OwnerRef::Group(g) => client.group_suppressions_list(g).await?,
    };

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