//! `voice_list_voices` — returns the curated voice catalog
//! filtered by optional locale_prefix / provider / cost_class.

use serde::Deserialize;
use serde_json::{json, Value};

use super::VoiceToolContext;
use crate::catalog::filter;
use crate::error::{Result, VoiceError};

#[derive(Debug, Deserialize, Default)]
#[serde(default)]
struct Args {
    locale_prefix: Option<String>,
    provider: Option<String>,
    cost_class: Option<String>,
}

pub async fn handle(_ctx: &VoiceToolContext, args: Value) -> Result<Value> {
    let parsed: Args = serde_json::from_value(args)
        .map_err(|e| VoiceError::InvalidParam(format!("voice_list_voices: {e}")))?;
    let entries = filter(
        parsed.locale_prefix.as_deref(),
        parsed.provider.as_deref(),
        parsed.cost_class.as_deref(),
    );
    Ok(json!({ "ok": true, "voices": entries }))
}
