#compdef openspec

# Zsh completion script for OpenSpec CLI
# Auto-generated - do not edit manually

_openspec() {
  local context state line
  typeset -A opt_args

  local -a commands
  commands=(
    'init:Initialize OpenSpec in your project'
    'update:Update OpenSpec instruction files'
    'list:List items (changes by default, or specs with --specs)'
    'view:Display an interactive dashboard of specs and changes'
    'validate:Validate changes and specs'
    'show:Show a change or spec'
    'archive:Archive a completed change and update main specs'
    'feedback:Submit feedback about OpenSpec'
    'change:Manage OpenSpec change proposals (deprecated)'
    'spec:Manage OpenSpec specifications'
    'completion:Manage shell completions for OpenSpec CLI'
    'config:View and modify global OpenSpec configuration'
    'schema:Manage workflow schemas'
  )

  _arguments -C \
    "1: :->command" \
    "*::arg:->args"

  case $state in
    command)
      _describe "openspec command" commands
      ;;
    args)
      case $words[1] in
        init)
          _openspec_init
          ;;
        update)
          _openspec_update
          ;;
        list)
          _openspec_list
          ;;
        view)
          _openspec_view
          ;;
        validate)
          _openspec_validate
          ;;
        show)
          _openspec_show
          ;;
        archive)
          _openspec_archive
          ;;
        feedback)
          _openspec_feedback
          ;;
        change)
          _openspec_change
          ;;
        spec)
          _openspec_spec
          ;;
        completion)
          _openspec_completion
          ;;
        config)
          _openspec_config
          ;;
        schema)
          _openspec_schema
          ;;
      esac
      ;;
  esac
}

_openspec_init() {
  _arguments \
    '--tools[Configure AI tools non-interactively (e.g., "all", "none", or comma-separated tool IDs)]:value:' \
    '*:path:_files'
}

_openspec_update() {
  _arguments \
    '*:path:_files'
}

_openspec_list() {
  _arguments \
    '--specs[List specs instead of changes]' \
    '--changes[List changes explicitly (default)]'
}

_openspec_view() {
  _arguments
}

_openspec_validate() {
  _arguments \
    '--all[Validate all changes and specs]' \
    '--changes[Validate all changes]' \
    '--specs[Validate all specs]' \
    '--type[Specify item type when ambiguous]:value:(change spec)' \
    '--strict[Enable strict validation mode]' \
    '--json[Output validation results as JSON]' \
    '--concurrency[Max concurrent validations (defaults to env OPENSPEC_CONCURRENCY or 6)]:value:' \
    '--no-interactive[Disable interactive prompts]' \
    '*: :_openspec_complete_items'
}

_openspec_show() {
  _arguments \
    '--json[Output as JSON]' \
    '--type[Specify item type when ambiguous]:value:(change spec)' \
    '--no-interactive[Disable interactive prompts]' \
    '--deltas-only[Show only deltas (JSON only, change-specific)]' \
    '--requirements-only[Alias for --deltas-only (deprecated, change-specific)]' \
    '--requirements[Show only requirements, exclude scenarios (JSON only, spec-specific)]' \
    '--no-scenarios[Exclude scenario content (JSON only, spec-specific)]' \
    '(-r --requirement)'{-r,--requirement}'[Show specific requirement by ID (JSON only, spec-specific)]:value:' \
    '*: :_openspec_complete_items'
}

_openspec_archive() {
  _arguments \
    '(-y --yes)'{-y,--yes}'[Skip confirmation prompts]' \
    '--skip-specs[Skip spec update operations]' \
    '--no-validate[Skip validation (not recommended)]' \
    '*: :_openspec_complete_changes'
}

_openspec_feedback() {
  _arguments \
    '--body[Detailed description for the feedback]:value:' \
    '*: :_default'
}

_openspec_change() {
  local context state line
  typeset -A opt_args

  local -a subcommands
  subcommands=(
    'show:Show a change proposal'
    'list:List all active changes (deprecated)'
    'validate:Validate a change proposal'
  )

  _arguments -C \
    "1: :->subcommand" \
    "*::arg:->args"

  case $state in
    subcommand)
      _describe "subcommand" subcommands
      ;;
    args)
      case $words[1] in
        show)
          _openspec_change_show
          ;;
        list)
          _openspec_change_list
          ;;
        validate)
          _openspec_change_validate
          ;;
      esac
      ;;
  esac
}

_openspec_change_show() {
  _arguments \
    '--json[Output as JSON]' \
    '--deltas-only[Show only deltas (JSON only)]' \
    '--requirements-only[Alias for --deltas-only (deprecated)]' \
    '--no-interactive[Disable interactive prompts]' \
    '*: :_openspec_complete_changes'
}

_openspec_change_list() {
  _arguments \
    '--json[Output as JSON]' \
    '--long[Show id and title with counts]'
}

_openspec_change_validate() {
  _arguments \
    '--strict[Enable strict validation mode]' \
    '--json[Output validation results as JSON]' \
    '--no-interactive[Disable interactive prompts]' \
    '*: :_openspec_complete_changes'
}

_openspec_spec() {
  local context state line
  typeset -A opt_args

  local -a subcommands
  subcommands=(
    'show:Show a specification'
    'list:List all specifications'
    'validate:Validate a specification'
  )

  _arguments -C \
    "1: :->subcommand" \
    "*::arg:->args"

  case $state in
    subcommand)
      _describe "subcommand" subcommands
      ;;
    args)
      case $words[1] in
        show)
          _openspec_spec_show
          ;;
        list)
          _openspec_spec_list
          ;;
        validate)
          _openspec_spec_validate
          ;;
      esac
      ;;
  esac
}

_openspec_spec_show() {
  _arguments \
    '--json[Output as JSON]' \
    '--requirements[Show only requirements, exclude scenarios (JSON only)]' \
    '--no-scenarios[Exclude scenario content (JSON only)]' \
    '(-r --requirement)'{-r,--requirement}'[Show specific requirement by ID (JSON only)]:value:' \
    '--no-interactive[Disable interactive prompts]' \
    '*: :_openspec_complete_specs'
}

_openspec_spec_list() {
  _arguments \
    '--json[Output as JSON]' \
    '--long[Show id and title with counts]'
}

_openspec_spec_validate() {
  _arguments \
    '--strict[Enable strict validation mode]' \
    '--json[Output validation results as JSON]' \
    '--no-interactive[Disable interactive prompts]' \
    '*: :_openspec_complete_specs'
}

_openspec_completion() {
  local context state line
  typeset -A opt_args

  local -a subcommands
  subcommands=(
    'generate:Generate completion script for a shell (outputs to stdout)'
    'install:Install completion script for a shell'
    'uninstall:Uninstall completion script for a shell'
  )

  _arguments -C \
    "1: :->subcommand" \
    "*::arg:->args"

  case $state in
    subcommand)
      _describe "subcommand" subcommands
      ;;
    args)
      case $words[1] in
        generate)
          _openspec_completion_generate
          ;;
        install)
          _openspec_completion_install
          ;;
        uninstall)
          _openspec_completion_uninstall
          ;;
      esac
      ;;
  esac
}

_openspec_completion_generate() {
  _arguments \
    '*:shell:(zsh bash fish powershell)'
}

_openspec_completion_install() {
  _arguments \
    '--verbose[Show detailed installation output]' \
    '*:shell:(zsh bash fish powershell)'
}

_openspec_completion_uninstall() {
  _arguments \
    '(-y --yes)'{-y,--yes}'[Skip confirmation prompts]' \
    '*:shell:(zsh bash fish powershell)'
}

_openspec_config() {
  local context state line
  typeset -A opt_args

  local -a subcommands
  subcommands=(
    'path:Show config file location'
    'list:Show all current settings'
    'get:Get a specific value (raw, scriptable)'
    'set:Set a value (auto-coerce types)'
    'unset:Remove a key (revert to default)'
    'reset:Reset configuration to defaults'
    'edit:Open config in $EDITOR'
    'profile:Configure workflow profile (interactive picker or preset shortcut)'
  )

  _arguments -C \
    '--scope[Config scope (only "global" supported currently)]:value:(global)' \
    "1: :->subcommand" \
    "*::arg:->args"

  case $state in
    subcommand)
      _describe "subcommand" subcommands
      ;;
    args)
      case $words[1] in
        path)
          _openspec_config_path
          ;;
        list)
          _openspec_config_list
          ;;
        get)
          _openspec_config_get
          ;;
        set)
          _openspec_config_set
          ;;
        unset)
          _openspec_config_unset
          ;;
        reset)
          _openspec_config_reset
          ;;
        edit)
          _openspec_config_edit
          ;;
        profile)
          _openspec_config_profile
          ;;
      esac
      ;;
  esac
}

_openspec_config_path() {
  _arguments
}

_openspec_config_list() {
  _arguments \
    '--json[Output as JSON]'
}

_openspec_config_get() {
  _arguments \
    '*: :_default'
}

_openspec_config_set() {
  _arguments \
    '--string[Force value to be stored as string]' \
    '--allow-unknown[Allow setting unknown keys]' \
    '*: :_default'
}

_openspec_config_unset() {
  _arguments \
    '*: :_default'
}

_openspec_config_reset() {
  _arguments \
    '--all[Reset all configuration (required)]' \
    '(-y --yes)'{-y,--yes}'[Skip confirmation prompts]'
}

_openspec_config_edit() {
  _arguments
}

_openspec_config_profile() {
  _arguments
}

_openspec_schema() {
  local context state line
  typeset -A opt_args

  local -a subcommands
  subcommands=(
    'which:Show where a schema resolves from'
    'validate:Validate a schema structure and templates'
    'fork:Copy an existing schema to project for customization'
    'init:Create a new project-local schema'
  )

  _arguments -C \
    "1: :->subcommand" \
    "*::arg:->args"

  case $state in
    subcommand)
      _describe "subcommand" subcommands
      ;;
    args)
      case $words[1] in
        which)
          _openspec_schema_which
          ;;
        validate)
          _openspec_schema_validate
          ;;
        fork)
          _openspec_schema_fork
          ;;
        init)
          _openspec_schema_init
          ;;
      esac
      ;;
  esac
}

_openspec_schema_which() {
  _arguments \
    '--json[Output as JSON]' \
    '--all[List all schemas with their resolution sources]' \
    '*: :_default'
}

_openspec_schema_validate() {
  _arguments \
    '--json[Output as JSON]' \
    '--verbose[Show detailed validation steps]' \
    '*: :_default'
}

_openspec_schema_fork() {
  _arguments \
    '--json[Output as JSON]' \
    '--force[Overwrite existing destination]' \
    '*: :_default'
}

_openspec_schema_init() {
  _arguments \
    '--json[Output as JSON]' \
    '--description[Schema description]:value:' \
    '--artifacts[Comma-separated artifact IDs]:value:' \
    '--default[Set as project default schema]' \
    '--no-default[Do not prompt to set as default]' \
    '--force[Overwrite existing schema]' \
    '*: :_default'
}

# Dynamic completion helpers

# Use openspec __complete to get available changes
_openspec_complete_changes() {
  local -a changes
  while IFS=$'\t' read -r id desc; do
    changes+=("$id:$desc")
  done < <(openspec __complete changes 2>/dev/null)
  _describe "change" changes
}

# Use openspec __complete to get available specs
_openspec_complete_specs() {
  local -a specs
  while IFS=$'\t' read -r id desc; do
    specs+=("$id:$desc")
  done < <(openspec __complete specs 2>/dev/null)
  _describe "spec" specs
}

# Get both changes and specs
_openspec_complete_items() {
  local -a items
  while IFS=$'\t' read -r id desc; do
    items+=("$id:$desc")
  done < <(openspec __complete changes 2>/dev/null)
  while IFS=$'\t' read -r id desc; do
    items+=("$id:$desc")
  done < <(openspec __complete specs 2>/dev/null)
  _describe "item" items
}
compdef _openspec openspec

