Feature: Resource CLI commands
  As a CleverAgents user
  I want to manage resources and resource types via the CLI
  So that I can register, inspect, and remove resource types and instances

  Background:
    Given a fresh in-memory resource registry

  # ---- Resource Type List ----

  Scenario: List resource types shows built-in types after init
    When I run resource type list
    Then the resource output should contain "git-checkout"
    And the resource output should contain "fs-directory"

  @tdd_issue @tdd_issue_4261 @tdd_expected_fail
  Scenario: List resource types in JSON format
    Given built-in types are bootstrapped
    When I run resource type list with format "json"
    Then the resource output should be valid JSON
    And the resource JSON output should contain key "name"

  # ---- Resource Type Show ----

  Scenario: Show a built-in resource type
    Given built-in types are bootstrapped
    When I run resource type show "git-checkout" using default format
    Then the resource output should contain "git-checkout"
    And the resource output should contain "physical"

  Scenario: Show a non-existent resource type
    When I run resource type show "nonexistent-type" using default format
    Then the resource command should fail
    And the resource output should contain "not found"

  Scenario: Show resource type in JSON format
    Given built-in types are bootstrapped
    When I run resource type show "git-checkout" using format "json"
    Then the resource output should be valid JSON

  # ---- Resource Type Add ----

  Scenario: Add a custom resource type from YAML
    Given a valid custom resource type YAML file
    When I run resource type add with the config file
    Then the resource output should contain "Registered resource type"

  Scenario: Add resource type with missing config file
    When I run resource type add with a nonexistent config file
    Then the resource command should fail
    And the resource output should contain "not found"

  # ---- Resource Type Remove ----

  Scenario: Remove a custom resource type
    Given a valid custom resource type YAML file
    And I run resource type add with the config file
    When I run resource type remove "test/custom-type" with yes flag
    Then the resource output should contain "Removed resource type"

  Scenario: Cannot remove a built-in resource type
    Given built-in types are bootstrapped
    When I run resource type remove "git-checkout" with yes flag
    Then the resource command should fail
    And the resource output should contain "Cannot remove built-in"

  # ---- Resource Add ----

  Scenario: Add a git-checkout resource
    Given built-in types are bootstrapped
    When I run resource add "git-checkout" "local/my-repo" with path "/tmp/repo"
    Then the resource output should contain "Added resource"
    And the resource output should contain "local/my-repo"

  Scenario: Add a resource with non-existent type
    When I run resource add "nonexistent" "local/test" with path "/tmp"
    Then the resource command should fail
    And the resource output should contain "not found"

  # ---- Resource List ----

  Scenario: List resources when empty
    When I run resource list
    Then the resource output should contain "No resources found"

  Scenario: List resources after adding one
    Given built-in types are bootstrapped
    And I run resource add "git-checkout" "local/my-repo" with path "/tmp/repo"
    When I run resource list
    Then the resource output should contain "local/my-repo"
    And the resource output should contain "git-checkout"

  Scenario: List resources filtered by type
    Given built-in types are bootstrapped
    And I run resource add "git-checkout" "local/my-repo" with path "/tmp/repo"
    When I run resource list with type filter "git-checkout"
    Then the resource output should contain "local/my-repo"

  Scenario: List resources in JSON format
    Given built-in types are bootstrapped
    And I run resource add "git-checkout" "local/test-res" with path "/tmp/test"
    When I run resource list with format "json"
    Then the resource output should be valid JSON

  # ---- Resource Show ----

  Scenario: Show a resource by name
    Given built-in types are bootstrapped
    And I run resource add "git-checkout" "local/show-test" with path "/tmp/show"
    When I run resource show "local/show-test" using default format
    Then the resource output should contain "local/show-test"
    And the resource output should contain "git-checkout"

  Scenario: Show a non-existent resource
    When I run resource show "nonexistent-resource" using default format
    Then the resource command should fail
    And the resource output should contain "not found"

  Scenario: Show resource in JSON format
    Given built-in types are bootstrapped
    And I run resource add "git-checkout" "local/json-res" with path "/tmp/json"
    When I run resource show "local/json-res" using format "json"
    Then the resource output should be valid JSON

  # ---- Resource Remove ----

  Scenario: Remove a resource
    Given built-in types are bootstrapped
    And I run resource add "git-checkout" "local/remove-me" with path "/tmp/rm"
    When I run resource remove "local/remove-me" with yes flag
    Then the resource output should contain "Removed resource"

  Scenario: Remove a non-existent resource
    When I run resource remove "nonexistent" with yes flag
    Then the resource command should fail
    And the resource output should contain "not found"
