---
to: "{{ project_name }}/src/cmds/{{ noun }}/{{ verb }}.rs"
vars:
  noun: "resource"
  verb: "update"
  noun_description: "resource"
---
//! {{ verb | capitalize }} {{ noun_description }} command

use clap_noun_verb_macros::verb;
use clap_noun_verb::Result;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct UpdateResult {
    id: String,
    changes: Vec<String>,
    message: String,
    dry_run: bool,
}

/// Update a {{ noun_description }}
#[verb] // Verb "update" auto-inferred, noun "{{ noun }}" auto-inferred from directory
pub fn update_{{ noun }}(
    /// ID or name of the {{ noun_description }}
    #[arg(index = 0)]
    id: String,
    /// New name
    #[arg(short, long)]
    name: Option<String>,
    /// New description
    #[arg(short, long)]
    description: Option<String>,
    /// Dry run (don't apply changes)
    #[arg(long)]
    dry_run: bool,
    /// Enable verbose output
    #[arg(short, long)]
    verbose: bool,
) -> Result<UpdateResult> {
    if verbose {
        eprintln!("Updating {{ noun_description }}: {}", id);
    }

    // TODO: Implement update logic here
    let mut changes = Vec::new();

    if let Some(ref new_name) = name {
        changes.push(format!("name: {}", new_name));
    }

    if let Some(ref new_desc) = description {
        changes.push(format!("description: {}", new_desc));
    }

    let message = if changes.is_empty() {
        "No changes specified".to_string()
    } else if dry_run {
        format!("Would update {{ noun_description }} '{}'", id)
    } else {
        format!("{{ noun | capitalize }} '{}' updated successfully!", id)
    };

    Ok(UpdateResult {
        id,
        changes,
        message,
        dry_run,
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_{{ verb }}_basic() {
        let result = update_{{ noun }}(
            "test-123".to_string(),
            Some("new-name".to_string()),
            None,
            true,
            false,
        );
        assert!(result.is_ok());
        let output = result.unwrap();
        assert_eq!(output.id, "test-123");
        assert!(output.dry_run);
    }
}
