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

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

#[derive(Debug, Serialize)]
pub struct {{ noun | capitalize }}Item {
    id: String,
    name: String,
    description: String,
}

#[derive(Debug, Serialize)]
pub struct ListResult {
    items: Vec<{{ noun | capitalize }}Item>,
    total: usize,
    filtered: usize,
}

/// List all {{ noun_description }}s
#[verb] // Verb "list" auto-inferred, noun "{{ noun }}" auto-inferred from directory
pub fn list_{{ noun }}s(
    /// Filter by name pattern
    #[arg(short, long)]
    filter: Option<String>,
    /// Maximum number of items to display
    #[arg(short, long)]
    limit: Option<usize>,
    /// Show all fields
    #[arg(short, long)]
    all: bool,
) -> Result<ListResult> {
    // TODO: Implement list logic here
    let all_items = vec![
        {{ noun | capitalize }}Item {
            id: "{{ noun }}-1".to_string(),
            name: "{{ noun }}-1".to_string(),
            description: "First {{ noun_description }}".to_string(),
        },
        {{ noun | capitalize }}Item {
            id: "{{ noun }}-2".to_string(),
            name: "{{ noun }}-2".to_string(),
            description: "Second {{ noun_description }}".to_string(),
        },
        {{ noun | capitalize }}Item {
            id: "{{ noun }}-3".to_string(),
            name: "{{ noun }}-3".to_string(),
            description: "Third {{ noun_description }}".to_string(),
        },
    ];

    let filtered_items: Vec<_> = if let Some(ref filter_pattern) = filter {
        all_items
            .into_iter()
            .filter(|item| item.name.contains(filter_pattern))
            .collect()
    } else {
        all_items
    };

    let limited_items = if let Some(limit_count) = limit {
        filtered_items.into_iter().take(limit_count).collect()
    } else {
        filtered_items
    };

    Ok(ListResult {
        total: 3, // Would come from actual data source
        filtered: limited_items.len(),
        items: limited_items,
    })
}

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

    #[test]
    fn test_{{ verb }}_basic() {
        let result = list_{{ noun }}s(None, None, false);
        assert!(result.is_ok());
        let output = result.unwrap();
        assert_eq!(output.items.len(), 3);
    }

    #[test]
    fn test_{{ verb }}_with_filter() {
        let result = list_{{ noun }}s(Some("{{ noun }}-1".to_string()), None, false);
        assert!(result.is_ok());
        let output = result.unwrap();
        assert_eq!(output.filtered, 1);
    }
}
