use serde::Deserialize;
use serde_json::json;

use super::{common, ToolResult};

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct CopyParams {
    pub from: String,
    pub to: String,
    #[serde(default)]
    pub force: bool,
}

pub async fn execute(params: CopyParams) -> ToolResult {
    common::validate_secret_name(&params.from, "from")?;
    common::validate_secret_name(&params.to, "to")?;

    let vault = envseal::vault::Vault::open_default().map_err(|e| e.to_string())?;
    envseal::ops::copy_secret(&vault, &params.from, &params.to, params.force)
        .map_err(|e| e.to_string())?;

    Ok(json!({
        "copied": true,
        "from": params.from,
        "to": params.to
    }))
}
