#compdef radp-bf

# Zsh completion script for radp-bf
# Generated by radp-bash-framework

_radp_bf_completion() {
    _arguments -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '1:shell:(bash zsh)'
}

_radp_bf_path() {
    _arguments -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '1:name:(init launcher root resolve)'
}

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

    _arguments -C -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '1: :->command' \
        '*:: :->args'

    case "$state" in
        command)
            local commands=(
                'new:Create a new CLI project based on radp-bash-framework'
                'upgrade:Upgrade an existing CLI project to latest scaffold'
            )
            _describe 'subcommand' commands
            ;;
        args)
            local cmd_func="_radp_bf_scaffold_${words[1]//-/_}"
            if (( $+functions[$cmd_func] )); then
                $cmd_func
            else
                _files
            fi
            ;;
    esac
}

_radp_bf_scaffold_new() {
    _arguments -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '1:name:_files' \
        '2:dir:_files'
}

_radp_bf_scaffold_upgrade() {
    _arguments -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '--dry-run[Show changes without applying]' \
        '--force[Overwrite user-modified files]' \
        '--diff[Show file differences]' \
        '1:dir:_files' \
        '*:components:(entry ide gitignore version workflows packaging globals all)'
}

_radp_bf_upgrade() {
    _arguments -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '--check[Only check for updates]' \
        '--force[Force upgrade even if at latest]' \
        '(-y --yes)'{-y,--yes}'[Skip confirmation prompt]' \
        '--version[Target specific version]:version:' \
        '*:file:_files'
}

_radp_bf_version() {
    _arguments -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '*:file:_files'
}

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

    # Workaround: Handle option prefix completion explicitly
    # Without this, -<TAB> may fall through to command completion
    # because _arguments -C doesn't trigger option completion for
    # incomplete option prefixes when positional args are specified
    if [[ $CURRENT -eq 2 && "${words[CURRENT]}" == -* ]]; then
        _arguments -s \
            '(-h --help)'{-h,--help}'[Show help]' \
            '--version[Show version]' \
        '(-q --quiet)'{-q,--quiet}'[Enable quiet mode]' \
        '(-v --verbose)'{-v,--verbose}'[Enable verbose output]' \
        '--debug[Enable debug output]' \
        '--show-config[Show configuration]' \
        '--all[Show all (with --show-config)]' \
        '--json[Output as JSON (with --show-config)]' \
        && return
    fi

    _arguments -C -s \
        '(-h --help)'{-h,--help}'[Show help]' \
        '--version[Show version]' \
        '(-q --quiet)'{-q,--quiet}'[Enable quiet mode]' \
        '(-v --verbose)'{-v,--verbose}'[Enable verbose output]' \
        '--debug[Enable debug output]' \
        '--show-config[Show configuration]' \
        '--all[Show all (with --show-config)]' \
        '--json[Output as JSON (with --show-config)]' \
        '1: :->command' \
        '*:: :->args'

    case "$state" in
        command)
            local commands=(
                'completion:Generate shell completion script for radp-bf'
                'path:Print framework path (init|launcher|root|resolve)'
                'scaffold:Manage scaffold'
                'upgrade:Upgrade radp-bf to the latest version'
                'version:Show radp-bash-framework version'
            )
            _describe 'command' commands
            ;;
        args)
            local cmd_func="_radp_bf_${words[1]//-/_}"
            if (( $+functions[$cmd_func] )); then
                $cmd_func
            else
                _files
            fi
            ;;
    esac
}

_radp_bf "$@"
