#compdef aineos
# AINEOS CLI zsh completion
# Source: source /path/to/_aineos
# Or install: aineos completion zsh > /usr/local/share/zsh/site-functions/_aineos

_aineos() {
  local context state state_descr line
  typeset -A opt_args

  local -a global_opts
  global_opts=(
    '(-v --version)'{-v,--version}'[显示版本信息]'
    '--help[显示帮助信息]'
    '--json[JSON 格式输出]'
    '(-w --workspace)'{-w,--workspace}'[目标工作空间]:workspace:'
  )

  local -a commands
  commands=(
    'list:列出 Truth Store 资产'
    'read:读取资产内容'
    'write:写入资产'
    'diff:比较资产差异'
    'init:初始化 AINEOS 项目'
    'config:管理配置'
    'check:运行一致性检查'
    'audit:查询审计日志'
    'status:显示系统状态'
    'propagate:变更影响分析'
    'verify:UI-SPEC 量化验证'
    'create:从模板创建资产'
    'predict:预测资产风险评分'
    'heal:自动修复一致性问题'
    'notify:管理通知通道'
    'run:执行技能和管线'
    'auto:自动一致性循环'
    'completion:生成 Shell 补全脚本'
  )

  _arguments -C \
    $global_opts \
    '(-):command:->command' \
    '(-)*:: :->arg'

  case $state in
    command)
      _describe '命令' commands
      ;;
    arg)
      local cur="${words[$CURRENT]}"
      local prev="${words[$CURRENT-1]}"

      case $prev in
        completion)
          _values 'shell' bash zsh
          ;;
        list)
          _values '选项' --type --status --json
          ;;
        init)
          _values '选项' --force '--template[模板类型]:template:(crud-api auth-flow microservice)' --with-git-hooks
          ;;
        config)
          _values '子命令' get set list
          ;;
        check)
          _values '选项' --rules --fix '--format[输出格式]:format:(text json)' --output --judge --judge-mock --judge-rules
          ;;
        audit)
          _values '子命令' query stats history recent
          ;;
        propagate)
          _values '选项' '--format[输出格式]:format:(text json)' --deep
          ;;
        verify)
          _values '子命令' ui-spec design tests report
          ;;
        create)
          _values '类型' BRD API-SPEC SCHEMA DESIGN UI-SPEC DOCUMENT TEST-PLAN TEST-CASE
          ;;
        predict)
          _values '选项' --risk-threshold --list-risks --watch --watch-interval
          ;;
        heal)
          _values '选项' --dry-run --apply '--mode[mode]:mode:(auto review suggestion)' --rules
          ;;
        notify)
          _values '子命令' list setup ui test remove
          ;;
        run)
          _values '子命令' list info pipeline
          ;;
        auto)
          _values '选项' --dry-run --apply --mode --risk-threshold --watch --deep
          ;;
        *)
          # Default to subcommand names
          local -a subcmds=()
          for cmd in list read write diff init config check audit status propagate verify create predict heal notify run auto completion; do
            subcmds+=($cmd)
          done
          _describe '命令' subcmds
          ;;
      esac
      ;;
  esac
}

_aineos
